@vanyamate/sec 0.3.1-batch-beta.6 → 0.3.1-batch-beta.8

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