@vanyamate/sec 0.3.1-batch-beta.2 → 0.3.1-batch-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let w=0,A=new Map;const E=()=>w+=1,p=()=>{w-=1,m()&&B()},m=()=>w==0,k=(o,n)=>{m()?o():A.set(n,o)},B=()=>{A.forEach(o=>o()),A.clear()},i=function(o,n){o&&n()},y=function(o,n={enabled:!0,instantListenerExecution:!1}){const c=new Set;let l,{enabled:t=!0,instantListenerExecution:f=!1}=n;const e={on:(r,s,a)=>(s==="onBefore"?r.onBefore((...u)=>i(t,()=>e.set(a(o,{args:u})))):s==="onSuccess"?r.onSuccess((u,...b)=>i(t,()=>e.set(a(o,{result:u,args:b})))):s==="onError"?r.onError((u,...b)=>i(t,()=>e.set(a(o,{error:u,args:b})))):r.onFinally((...u)=>i(t,()=>e.set(a(o,{args:u})))),e),get(){return o},set(r){o=r,k(()=>{l!=o&&(l=o,c.forEach(s=>s(o)))},this)},subscribe(r){return c.add(r),f&&r(o),()=>c.delete(r)},enableOn(r,s){return r.subscribe(()=>{t=!0,s!==void 0&&(E(),queueMicrotask(()=>{p(),e.set(s)}))}),e},disableOn(r,s){return r.subscribe(()=>{t=!1,s!==void 0&&(E(),queueMicrotask(()=>{p(),e.set(s)}))}),e}};return e},h=function(){return{afterAll:[],beforeAll:[],other:[]}},C=function(o){const n=h(),c=h(),l=h(),t=h(),f=async function(...e){E();try{return n.beforeAll.forEach(r=>r(...e)),n.other.forEach(r=>r(...e)),n.afterAll.forEach(r=>r(...e)),await o(...e).then(r=>(c.beforeAll.forEach(s=>s(r,...e)),c.other.forEach(s=>s(r,...e)),c.afterAll.forEach(s=>s(r,...e)),r)).catch(r=>{throw l.beforeAll.forEach(s=>s(r,...e)),l.other.forEach(s=>s(r,...e)),l.afterAll.forEach(s=>s(r,...e)),r}).finally(()=>{t.beforeAll.forEach(r=>r(...e)),t.other.forEach(r=>r(...e)),t.afterAll.forEach(r=>r(...e))})}finally{p()}};return f.onBefore=(e,r)=>{switch(r){case"beforeAll":n.beforeAll.push(e);break;case"afterAll":n.afterAll.push(e);break;default:n.other.push(e)}},f.onSuccess=(e,r)=>{switch(r){case"beforeAll":c.beforeAll.push(e);break;case"afterAll":c.afterAll.push(e);break;default:c.other.push(e)}},f.onError=(e,r)=>{switch(r){case"beforeAll":l.beforeAll.push(e);break;case"afterAll":l.afterAll.push(e);break;default:l.other.push(e)}},f.onFinally=(e,r)=>{switch(r){case"beforeAll":t.beforeAll.push(e);break;case"afterAll":t.afterAll.push(e);break;default:t.other.push(e)}},f},S=function(o,n,c=!0){console.log("Combine",o,n,c);let l=n(o);const t=[];o.forEach(e=>{e.subscribe(()=>{i(c,()=>{l=n(o),t.forEach(r=>r(l))})})});const f={on:()=>{throw new Error("Cannot call 'on' on combined store")},get(){return l},set(){throw new Error("Cannot call 'set' on combined store")},subscribe(e){return t.push(e),()=>{const r=t.indexOf(e);~r&&t.splice(r,1)}},enableOn(e){return e.subscribe(()=>c=!0),f},disableOn(e){return e.subscribe(()=>c=!1),f}};return f},F=function(o){const n=[],c={on:(l,t)=>(l==="onBefore"?t.onBefore(()=>n.forEach(f=>f()),o):l==="onSuccess"?t.onSuccess(()=>n.forEach(f=>f()),o):l==="onError"?t.onError(()=>n.forEach(f=>f()),o):t.onFinally(()=>n.forEach(f=>f()),o),c),subscribe:l=>{n.push(l)}};return c},d=function(o){return()=>o},O=function(o){const n=y(!1);return o.forEach(c=>{n.on(c,"onBefore",d(!0)),n.on(c,"onFinally",d(!1))}),n},x=function(){return(o,{result:n})=>n};exports.combine=S;exports.effect=C;exports.enableCheck=i;exports.marker=F;exports.pending=O;exports.result=x;exports.store=y;exports.to=d;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let d=0,E=new Map;const S=()=>d+=1,k=()=>{d-=1,m()&&B()},m=()=>d===0,p=(o,t)=>{S(),E.set(o,t),queueMicrotask(k)},B=()=>{E.forEach(o=>o()),E.clear()},i=function(o,t){o&&t()},w=function(o,t={enabled:!0,instantListenerExecution:!1}){const f=new Set;let s=o,{enabled:c=!0,instantListenerExecution:l=!1}=t;const r={on:(e,n,u)=>(n==="onBefore"?e.onBefore((...a)=>i(c,()=>r.set(u(o,{args:a})))):n==="onSuccess"?e.onSuccess((a,...b)=>i(c,()=>r.set(u(o,{result:a,args:b})))):n==="onError"?e.onError((a,...b)=>i(c,()=>r.set(u(o,{error:a,args:b})))):e.onFinally((...a)=>i(c,()=>r.set(u(o,{args:a})))),r),get(){return o},set(e){o=e,p(this,()=>{s!==o&&(s=o,f.forEach(n=>n(o)))})},subscribe(e){return f.add(e),l&&e(o),()=>f.delete(e)},enableOn(e,n){return e.subscribe(()=>{c=!0,n!==void 0&&r.set(n)}),r},disableOn(e,n){return e.subscribe(()=>{c=!1,n!==void 0&&r.set(n)}),r}};return r},h=function(){return{afterAll:[],beforeAll:[],other:[]}},y=function(o){const t=h(),f=h(),s=h(),c=h(),l=async function(...r){return t.beforeAll.forEach(e=>e(...r)),t.other.forEach(e=>e(...r)),t.afterAll.forEach(e=>e(...r)),o(...r).then(e=>(f.beforeAll.forEach(n=>n(e,...r)),f.other.forEach(n=>n(e,...r)),f.afterAll.forEach(n=>n(e,...r)),e)).catch(e=>{throw s.beforeAll.forEach(n=>n(e,...r)),s.other.forEach(n=>n(e,...r)),s.afterAll.forEach(n=>n(e,...r)),e}).finally(()=>{c.beforeAll.forEach(e=>e(...r)),c.other.forEach(e=>e(...r)),c.afterAll.forEach(e=>e(...r))})};return l.onBefore=(r,e)=>{switch(e){case"beforeAll":t.beforeAll.push(r);break;case"afterAll":t.afterAll.push(r);break;default:t.other.push(r)}},l.onSuccess=(r,e)=>{switch(e){case"beforeAll":f.beforeAll.push(r);break;case"afterAll":f.afterAll.push(r);break;default:f.other.push(r)}},l.onError=(r,e)=>{switch(e){case"beforeAll":s.beforeAll.push(r);break;case"afterAll":s.afterAll.push(r);break;default:s.other.push(r)}},l.onFinally=(r,e)=>{switch(e){case"beforeAll":c.beforeAll.push(r);break;case"afterAll":c.afterAll.push(r);break;default:c.other.push(r)}},l},C=function(o,t,f={enabled:!0,instantListenerExecution:!1}){let s,c;s=c=t(o);const l=new Set;let{enabled:r=!0,instantListenerExecution:e=!1}=f;o.forEach(u=>{u.subscribe(()=>{i(r,()=>{p(n,()=>{s=t(o),s!==c&&(c=s,l.forEach(a=>a(s)))})})})});const n={on:()=>{throw new Error("Cannot call 'on' on combined store")},get(){return s},set(){throw new Error("Cannot call 'set' on combined store")},subscribe(u){return l.add(u),e&&u(s),()=>l.delete(u)},enableOn(u){return u.subscribe(()=>r=!0),n},disableOn(u){return u.subscribe(()=>r=!1),n}};return n},F=function(o){const t=[],f={on:(s,c)=>(s==="onBefore"?c.onBefore(()=>t.forEach(l=>l()),o):s==="onSuccess"?c.onSuccess(()=>t.forEach(l=>l()),o):s==="onError"?c.onError(()=>t.forEach(l=>l()),o):c.onFinally(()=>t.forEach(l=>l()),o),f),subscribe:s=>{t.push(s)}};return f},A=function(o){return()=>o},L=function(o){const t=w(!1);return o.forEach(f=>{t.on(f,"onBefore",A(!0)),t.on(f,"onFinally",A(!1))}),t},x=function(){return(o,{result:t})=>t};exports.combine=C;exports.effect=y;exports.enableCheck=i;exports.marker=F;exports.pending=L;exports.result=x;exports.store=w;exports.to=A;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare const combine: <State, States extends Array<any>>(stores: { [Index in keyof States]: Store<States[Index]>; }, callback: (stores: { [K in keyof States]: Store<States[K]>; }) => State, enabled?: boolean) => Store<State>;
1
+ export declare const combine: <State, States extends Array<any>>(stores: { [Index in keyof States]: Store<States[Index]>; }, callback: (stores: { [K in keyof States]: Store<States[K]>; }) => State, options?: StoreOptions) => Store<State>;
2
2
 
3
3
  export declare type Effect<AsyncAction extends EffectAction> = {
4
4
  (...args: Parameters<AsyncAction>): Promise<Awaited<ReturnType<AsyncAction>>>;
package/dist/index.js CHANGED
@@ -1,78 +1,74 @@
1
- let d = 0, A = /* @__PURE__ */ new Map();
2
- const E = () => d += 1, p = () => {
3
- d -= 1, B() && C();
4
- }, B = () => d == 0, y = (o, n) => {
5
- B() ? o() : A.set(n, o);
6
- }, C = () => {
7
- A.forEach((o) => o()), A.clear();
8
- }, i = function(o, n) {
9
- o && n();
10
- }, k = function(o, n = { enabled: !0, instantListenerExecution: !1 }) {
11
- const c = /* @__PURE__ */ new Set();
12
- let l, { enabled: t = !0, instantListenerExecution: f = !1 } = n;
13
- const e = {
14
- on: (r, s, a) => (s === "onBefore" ? r.onBefore(
15
- (...u) => i(
16
- t,
17
- () => e.set(
18
- a(o, { args: u })
1
+ let A = 0, E = /* @__PURE__ */ new Map();
2
+ const w = () => A += 1, B = () => {
3
+ A -= 1, S() && k();
4
+ }, S = () => A === 0, p = (o, t) => {
5
+ w(), E.set(o, t), queueMicrotask(B);
6
+ }, k = () => {
7
+ E.forEach((o) => o()), E.clear();
8
+ }, i = function(o, t) {
9
+ o && t();
10
+ }, C = function(o, t = { enabled: !0, instantListenerExecution: !1 }) {
11
+ const f = /* @__PURE__ */ new Set();
12
+ let s = o, { enabled: c = !0, instantListenerExecution: l = !1 } = t;
13
+ const r = {
14
+ on: (e, n, u) => (n === "onBefore" ? e.onBefore(
15
+ (...a) => i(
16
+ c,
17
+ () => r.set(
18
+ u(o, { args: a })
19
19
  )
20
20
  )
21
- ) : s === "onSuccess" ? r.onSuccess(
22
- (u, ...b) => i(
23
- t,
24
- () => e.set(
25
- a(o, {
26
- result: u,
21
+ ) : n === "onSuccess" ? e.onSuccess(
22
+ (a, ...b) => i(
23
+ c,
24
+ () => r.set(
25
+ u(o, {
26
+ result: a,
27
27
  args: b
28
28
  })
29
29
  )
30
30
  )
31
- ) : s === "onError" ? r.onError(
32
- (u, ...b) => i(
33
- t,
34
- () => e.set(
35
- a(o, {
36
- error: u,
31
+ ) : n === "onError" ? e.onError(
32
+ (a, ...b) => i(
33
+ c,
34
+ () => r.set(
35
+ u(o, {
36
+ error: a,
37
37
  args: b
38
38
  })
39
39
  )
40
40
  )
41
- ) : r.onFinally(
42
- (...u) => i(
43
- t,
44
- () => e.set(
45
- a(o, { args: u })
41
+ ) : e.onFinally(
42
+ (...a) => i(
43
+ c,
44
+ () => r.set(
45
+ u(o, { args: a })
46
46
  )
47
47
  )
48
- ), e),
48
+ ), r),
49
49
  get() {
50
50
  return o;
51
51
  },
52
- set(r) {
53
- o = r, y(() => {
54
- l != o && (l = o, c.forEach((s) => s(o)));
55
- }, this);
52
+ set(e) {
53
+ o = e, p(this, () => {
54
+ s !== o && (s = o, f.forEach((n) => n(o)));
55
+ });
56
56
  },
57
- subscribe(r) {
58
- return c.add(r), f && r(o), () => c.delete(r);
57
+ subscribe(e) {
58
+ return f.add(e), l && e(o), () => f.delete(e);
59
59
  },
60
- enableOn(r, s) {
61
- return r.subscribe(() => {
62
- t = !0, s !== void 0 && (E(), queueMicrotask(() => {
63
- p(), e.set(s);
64
- }));
65
- }), e;
60
+ enableOn(e, n) {
61
+ return e.subscribe(() => {
62
+ c = !0, n !== void 0 && r.set(n);
63
+ }), r;
66
64
  },
67
- disableOn(r, s) {
68
- return r.subscribe(() => {
69
- t = !1, s !== void 0 && (E(), queueMicrotask(() => {
70
- p(), e.set(s);
71
- }));
72
- }), e;
65
+ disableOn(e, n) {
66
+ return e.subscribe(() => {
67
+ c = !1, n !== void 0 && r.set(n);
68
+ }), r;
73
69
  }
74
70
  };
75
- return e;
71
+ return r;
76
72
  }, h = function() {
77
73
  return {
78
74
  afterAll: [],
@@ -80,123 +76,118 @@ const E = () => d += 1, p = () => {
80
76
  other: []
81
77
  };
82
78
  }, m = function(o) {
83
- const n = h(), c = h(), l = h(), t = h(), f = async function(...e) {
84
- E();
85
- try {
86
- return n.beforeAll.forEach((r) => r(...e)), n.other.forEach((r) => r(...e)), n.afterAll.forEach((r) => r(...e)), await o(...e).then((r) => (c.beforeAll.forEach((s) => s(r, ...e)), c.other.forEach((s) => s(r, ...e)), c.afterAll.forEach((s) => s(r, ...e)), r)).catch((r) => {
87
- throw l.beforeAll.forEach((s) => s(r, ...e)), l.other.forEach((s) => s(r, ...e)), l.afterAll.forEach((s) => s(r, ...e)), r;
88
- }).finally(() => {
89
- t.beforeAll.forEach((r) => r(...e)), t.other.forEach((r) => r(...e)), t.afterAll.forEach((r) => r(...e));
90
- });
91
- } finally {
92
- p();
93
- }
79
+ const t = h(), f = h(), s = h(), c = h(), l = async function(...r) {
80
+ return t.beforeAll.forEach((e) => e(...r)), t.other.forEach((e) => e(...r)), t.afterAll.forEach((e) => e(...r)), o(...r).then((e) => (f.beforeAll.forEach((n) => n(e, ...r)), f.other.forEach((n) => n(e, ...r)), f.afterAll.forEach((n) => n(e, ...r)), e)).catch((e) => {
81
+ throw s.beforeAll.forEach((n) => n(e, ...r)), s.other.forEach((n) => n(e, ...r)), s.afterAll.forEach((n) => n(e, ...r)), e;
82
+ }).finally(() => {
83
+ c.beforeAll.forEach((e) => e(...r)), c.other.forEach((e) => e(...r)), c.afterAll.forEach((e) => e(...r));
84
+ });
94
85
  };
95
- return f.onBefore = (e, r) => {
96
- switch (r) {
86
+ return l.onBefore = (r, e) => {
87
+ switch (e) {
97
88
  case "beforeAll":
98
- n.beforeAll.push(e);
89
+ t.beforeAll.push(r);
99
90
  break;
100
91
  case "afterAll":
101
- n.afterAll.push(e);
92
+ t.afterAll.push(r);
102
93
  break;
103
94
  default:
104
- n.other.push(e);
95
+ t.other.push(r);
105
96
  }
106
- }, f.onSuccess = (e, r) => {
107
- switch (r) {
97
+ }, l.onSuccess = (r, e) => {
98
+ switch (e) {
108
99
  case "beforeAll":
109
- c.beforeAll.push(e);
100
+ f.beforeAll.push(r);
110
101
  break;
111
102
  case "afterAll":
112
- c.afterAll.push(e);
103
+ f.afterAll.push(r);
113
104
  break;
114
105
  default:
115
- c.other.push(e);
106
+ f.other.push(r);
116
107
  }
117
- }, f.onError = (e, r) => {
118
- switch (r) {
108
+ }, l.onError = (r, e) => {
109
+ switch (e) {
119
110
  case "beforeAll":
120
- l.beforeAll.push(e);
111
+ s.beforeAll.push(r);
121
112
  break;
122
113
  case "afterAll":
123
- l.afterAll.push(e);
114
+ s.afterAll.push(r);
124
115
  break;
125
116
  default:
126
- l.other.push(e);
117
+ s.other.push(r);
127
118
  }
128
- }, f.onFinally = (e, r) => {
129
- switch (r) {
119
+ }, l.onFinally = (r, e) => {
120
+ switch (e) {
130
121
  case "beforeAll":
131
- t.beforeAll.push(e);
122
+ c.beforeAll.push(r);
132
123
  break;
133
124
  case "afterAll":
134
- t.afterAll.push(e);
125
+ c.afterAll.push(r);
135
126
  break;
136
127
  default:
137
- t.other.push(e);
128
+ c.other.push(r);
138
129
  }
139
- }, f;
140
- }, S = function(o, n, c = !0) {
141
- console.log("Combine", o, n, c);
142
- let l = n(o);
143
- const t = [];
144
- o.forEach((e) => {
145
- e.subscribe(() => {
146
- i(c, () => {
147
- l = n(o), t.forEach((r) => r(l));
130
+ }, l;
131
+ }, y = function(o, t, f = { enabled: !0, instantListenerExecution: !1 }) {
132
+ let s, c;
133
+ s = c = t(o);
134
+ const l = /* @__PURE__ */ new Set();
135
+ let { enabled: r = !0, instantListenerExecution: e = !1 } = f;
136
+ o.forEach((u) => {
137
+ u.subscribe(() => {
138
+ i(r, () => {
139
+ p(n, () => {
140
+ s = t(o), s !== c && (c = s, l.forEach((a) => a(s)));
141
+ });
148
142
  });
149
143
  });
150
144
  });
151
- const f = {
145
+ const n = {
152
146
  on: () => {
153
147
  throw new Error("Cannot call 'on' on combined store");
154
148
  },
155
149
  get() {
156
- return l;
150
+ return s;
157
151
  },
158
152
  set() {
159
153
  throw new Error("Cannot call 'set' on combined store");
160
154
  },
161
- subscribe(e) {
162
- return t.push(e), () => {
163
- const r = t.indexOf(e);
164
- ~r && t.splice(r, 1);
165
- };
155
+ subscribe(u) {
156
+ return l.add(u), e && u(s), () => l.delete(u);
166
157
  },
167
- enableOn(e) {
168
- return e.subscribe(() => c = !0), f;
158
+ enableOn(u) {
159
+ return u.subscribe(() => r = !0), n;
169
160
  },
170
- disableOn(e) {
171
- return e.subscribe(() => c = !1), f;
161
+ disableOn(u) {
162
+ return u.subscribe(() => r = !1), n;
172
163
  }
173
164
  };
174
- return f;
165
+ return n;
175
166
  }, x = function(o) {
176
- const n = [], c = {
177
- on: (l, t) => (l === "onBefore" ? t.onBefore(() => n.forEach((f) => f()), o) : l === "onSuccess" ? t.onSuccess(() => n.forEach((f) => f()), o) : l === "onError" ? t.onError(() => n.forEach((f) => f()), o) : t.onFinally(() => n.forEach((f) => f()), o), c),
178
- subscribe: (l) => {
179
- n.push(l);
167
+ const t = [], f = {
168
+ on: (s, c) => (s === "onBefore" ? c.onBefore(() => t.forEach((l) => l()), o) : s === "onSuccess" ? c.onSuccess(() => t.forEach((l) => l()), o) : s === "onError" ? c.onError(() => t.forEach((l) => l()), o) : c.onFinally(() => t.forEach((l) => l()), o), f),
169
+ subscribe: (s) => {
170
+ t.push(s);
180
171
  }
181
172
  };
182
- return c;
183
- }, w = function(o) {
173
+ return f;
174
+ }, d = function(o) {
184
175
  return () => o;
185
176
  }, F = function(o) {
186
- const n = k(!1);
187
- return o.forEach((c) => {
188
- n.on(c, "onBefore", w(!0)), n.on(c, "onFinally", w(!1));
189
- }), n;
190
- }, O = function() {
191
- return (o, { result: n }) => n;
177
+ const t = C(!1);
178
+ return o.forEach((f) => {
179
+ t.on(f, "onBefore", d(!0)), t.on(f, "onFinally", d(!1));
180
+ }), t;
181
+ }, L = function() {
182
+ return (o, { result: t }) => t;
192
183
  };
193
184
  export {
194
- S as combine,
185
+ y as combine,
195
186
  m as effect,
196
187
  i as enableCheck,
197
188
  x as marker,
198
189
  F as pending,
199
- O as result,
200
- k as store,
201
- w as to
190
+ L as result,
191
+ C as store,
192
+ d as to
202
193
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vanyamate/sec",
3
- "version": "0.3.1-batch-beta.2",
3
+ "version": "0.3.1-batch-beta.4",
4
4
  "description": "SEC. Store, Effect, Combine. Tiny state manager",
5
5
  "scripts": {
6
6
  "build": "vite build",