@vanyamate/sec 0.3.1-batch-beta.3 → 0.3.1-batch-beta.5

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