@vanyamate/sec 0.2.2 → 0.2.3

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