@vanyamate/sec 0.2.4 → 0.2.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"});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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=function(s,n){s&&n()},a=function(s,n=!0){const f=[],c={on:(o,t,e)=>(t==="onBefore"?o.onBefore((...r)=>u(n,()=>c.set(e(s,{args:r})))):t==="onSuccess"?o.onSuccess((r,...l)=>u(n,()=>c.set(e(s,{result:r,args:l})))):t==="onError"?o.onError((r,...l)=>u(n,()=>c.set(e(s,{error:r,args:l})))):o.onFinally((...r)=>u(n,()=>c.set(e(s,{args:r})))),c),get(){return s},set(o){s=o,f.forEach(t=>t(s))},subscribe(o){return f.push(o),()=>{const t=f.indexOf(o);~t&&f.splice(t,1)}},enableOn(o){return o.subscribe(()=>n=!0),c},disableOn(o){return o.subscribe(()=>n=!1),c}};return c},i=function(){return{afterAll:[],beforeAll:[],other:[]}},b=function(s){const n=i(),f=i(),c=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)),s(...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 c.beforeAll.forEach(l=>l(r,...e)),c.other.forEach(l=>l(r,...e)),c.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":c.beforeAll.push(e);break;case"afterAll":c.afterAll.push(e);break;default:c.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(s,n,f=!0){console.log("Combine",s,n,f);let c=n(s);const o=[];s.forEach(e=>{e.subscribe(()=>{u(f,()=>{c=n(s),o.forEach(r=>r(c))})})});const t={on:()=>{throw new Error("Cannot call 'on' on combined store")},get(){return c},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=!0),t},disableOn(e){return e.subscribe(()=>f=!1),t}};return t},E=function(s){const n=[],f={on:(c,o)=>(c==="onBefore"?o.onBefore(()=>n.forEach(t=>t()),s):c==="onSuccess"?o.onSuccess(()=>n.forEach(t=>t()),s):c==="onError"?o.onError(()=>n.forEach(t=>t()),s):o.onFinally(()=>n.forEach(t=>t()),s),f),subscribe:c=>{n.push(c)}};return f},h=function(s){return()=>s},p=function(s){const n=a(!1);return s.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.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, enabled?: boolean) => 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,19 +1,19 @@
1
- const u = function(c, n) {
2
- c && n();
3
- }, a = function(c, n = !0) {
4
- const f = [], t = {
1
+ const u = function(t, n) {
2
+ t && n();
3
+ }, a = function(t, n = !0) {
4
+ const f = [], c = {
5
5
  on: (o, s, e) => (s === "onBefore" ? o.onBefore(
6
6
  (...r) => u(
7
7
  n,
8
- () => t.set(
9
- e(c, { args: r })
8
+ () => c.set(
9
+ e(t, { args: r })
10
10
  )
11
11
  )
12
12
  ) : s === "onSuccess" ? o.onSuccess(
13
13
  (r, ...l) => u(
14
14
  n,
15
- () => t.set(
16
- e(c, {
15
+ () => c.set(
16
+ e(t, {
17
17
  result: r,
18
18
  args: l
19
19
  })
@@ -22,8 +22,8 @@ const u = function(c, n) {
22
22
  ) : s === "onError" ? o.onError(
23
23
  (r, ...l) => u(
24
24
  n,
25
- () => t.set(
26
- e(c, {
25
+ () => c.set(
26
+ e(t, {
27
27
  error: r,
28
28
  args: l
29
29
  })
@@ -32,16 +32,16 @@ const u = function(c, n) {
32
32
  ) : o.onFinally(
33
33
  (...r) => u(
34
34
  n,
35
- () => t.set(
36
- e(c, { args: r })
35
+ () => c.set(
36
+ e(t, { args: r })
37
37
  )
38
38
  )
39
- ), t),
39
+ ), c),
40
40
  get() {
41
- return c;
41
+ return t;
42
42
  },
43
43
  set(o) {
44
- c = o, f.forEach((s) => s(c));
44
+ t = o, f.forEach((s) => s(t));
45
45
  },
46
46
  subscribe(o) {
47
47
  return f.push(o), () => {
@@ -50,23 +50,23 @@ const u = function(c, n) {
50
50
  };
51
51
  },
52
52
  enableOn(o) {
53
- return o.subscribe(() => n = !0), t;
53
+ return o.subscribe(() => n = !0), c;
54
54
  },
55
55
  disableOn(o) {
56
- return o.subscribe(() => n = !1), t;
56
+ return o.subscribe(() => n = !1), c;
57
57
  }
58
58
  };
59
- return t;
59
+ return c;
60
60
  }, h = function() {
61
61
  return {
62
62
  afterAll: [],
63
63
  beforeAll: [],
64
64
  other: []
65
65
  };
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;
66
+ }, b = function(t) {
67
+ const n = h(), f = h(), c = 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)), t(...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 c.beforeAll.forEach((l) => l(r, ...e)), c.other.forEach((l) => l(r, ...e)), c.afterAll.forEach((l) => l(r, ...e)), r;
70
70
  }).finally(() => {
71
71
  o.beforeAll.forEach((r) => r(...e)), o.other.forEach((r) => r(...e)), o.afterAll.forEach((r) => r(...e));
72
72
  });
@@ -96,13 +96,13 @@ const u = function(c, n) {
96
96
  }, s.onError = (e, r) => {
97
97
  switch (r) {
98
98
  case "beforeAll":
99
- t.beforeAll.push(e);
99
+ c.beforeAll.push(e);
100
100
  break;
101
101
  case "afterAll":
102
- t.afterAll.push(e);
102
+ c.afterAll.push(e);
103
103
  break;
104
104
  default:
105
- t.other.push(e);
105
+ c.other.push(e);
106
106
  }
107
107
  }, s.onFinally = (e, r) => {
108
108
  switch (r) {
@@ -116,13 +116,14 @@ const u = function(c, n) {
116
116
  o.other.push(e);
117
117
  }
118
118
  }, s;
119
- }, A = function(c, n, f = !0) {
120
- let t = n(...c);
119
+ }, A = function(t, n, f = !0) {
120
+ console.log("Combine", t, n, f);
121
+ let c = n(t);
121
122
  const o = [];
122
- c.forEach((e) => {
123
+ t.forEach((e) => {
123
124
  e.subscribe(() => {
124
125
  u(f, () => {
125
- t = n(...c), o.forEach((r) => r(t));
126
+ c = n(t), o.forEach((r) => r(c));
126
127
  });
127
128
  });
128
129
  });
@@ -131,7 +132,7 @@ const u = function(c, n) {
131
132
  throw new Error("Cannot call 'on' on combined store");
132
133
  },
133
134
  get() {
134
- return t;
135
+ return c;
135
136
  },
136
137
  set() {
137
138
  throw new Error("Cannot call 'set' on combined store");
@@ -143,26 +144,26 @@ const u = function(c, n) {
143
144
  };
144
145
  },
145
146
  enableOn(e) {
146
- return e.subscribe(() => f = !1), s;
147
+ return e.subscribe(() => f = !0), s;
147
148
  },
148
149
  disableOn(e) {
149
- return e.subscribe(() => f = !0), s;
150
+ return e.subscribe(() => f = !1), s;
150
151
  }
151
152
  };
152
153
  return s;
153
- }, E = function(c) {
154
+ }, E = function(t) {
154
155
  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
+ on: (c, o) => (c === "onBefore" ? o.onBefore(() => n.forEach((s) => s()), t) : c === "onSuccess" ? o.onSuccess(() => n.forEach((s) => s()), t) : c === "onError" ? o.onError(() => n.forEach((s) => s()), t) : o.onFinally(() => n.forEach((s) => s()), t), f),
157
+ subscribe: (c) => {
158
+ n.push(c);
158
159
  }
159
160
  };
160
161
  return f;
161
- }, i = function(c) {
162
- return () => c;
163
- }, p = function(c) {
162
+ }, i = function(t) {
163
+ return () => t;
164
+ }, p = function(t) {
164
165
  const n = a(!1);
165
- return c.forEach((f) => {
166
+ return t.forEach((f) => {
166
167
  n.on(f, "onBefore", i(!0)), n.on(f, "onFinally", i(!1));
167
168
  }), n;
168
169
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vanyamate/sec",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "SEC. Store, Effect, Combine. Tiny state manager",
5
5
  "scripts": {
6
6
  "build": "vite build",