@vanyamate/sec 0.3.1-batch-beta.1 → 0.3.1-batch-beta.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"});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,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;
package/dist/index.js CHANGED
@@ -1,48 +1,48 @@
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 = () => {
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);
6
+ }, k = () => {
7
7
  A.forEach((o) => o()), A.clear();
8
- }, i = function(o, n) {
8
+ }, a = function(o, n) {
9
9
  o && n();
10
- }, k = function(o, n = { enabled: !0, instantListenerExecution: !1 }) {
10
+ }, C = function(o, n = { enabled: !0, instantListenerExecution: !1 }) {
11
11
  const c = /* @__PURE__ */ new Set();
12
- let l, { enabled: t = !0, instantListenerExecution: f = !1 } = n;
12
+ let l = o, { enabled: s = !0, instantListenerExecution: f = !1 } = n;
13
13
  const e = {
14
- on: (r, s, a) => (s === "onBefore" ? r.onBefore(
15
- (...u) => i(
16
- t,
14
+ on: (r, t, h) => (t === "onBefore" ? r.onBefore(
15
+ (...u) => a(
16
+ s,
17
17
  () => e.set(
18
- a(o, { args: u })
18
+ h(o, { args: u })
19
19
  )
20
20
  )
21
- ) : s === "onSuccess" ? r.onSuccess(
22
- (u, ...b) => i(
23
- t,
21
+ ) : t === "onSuccess" ? r.onSuccess(
22
+ (u, ...b) => a(
23
+ s,
24
24
  () => e.set(
25
- a(o, {
25
+ h(o, {
26
26
  result: u,
27
27
  args: b
28
28
  })
29
29
  )
30
30
  )
31
- ) : s === "onError" ? r.onError(
32
- (u, ...b) => i(
33
- t,
31
+ ) : t === "onError" ? r.onError(
32
+ (u, ...b) => a(
33
+ s,
34
34
  () => e.set(
35
- a(o, {
35
+ h(o, {
36
36
  error: u,
37
37
  args: b
38
38
  })
39
39
  )
40
40
  )
41
41
  ) : r.onFinally(
42
- (...u) => i(
43
- t,
42
+ (...u) => a(
43
+ s,
44
44
  () => e.set(
45
- a(o, { args: u })
45
+ h(o, { args: u })
46
46
  )
47
47
  )
48
48
  ), e),
@@ -50,47 +50,38 @@ const E = () => d += 1, p = () => {
50
50
  return o;
51
51
  },
52
52
  set(r) {
53
- o = r, y(() => {
54
- l != o && (l = o, c.forEach((s) => s(o)));
55
- }, this);
53
+ o = r, d(this, () => {
54
+ l != o && (l = o, c.forEach((t) => t(o)));
55
+ });
56
56
  },
57
57
  subscribe(r) {
58
58
  return c.add(r), f && r(o), () => c.delete(r);
59
59
  },
60
- enableOn(r, s) {
60
+ enableOn(r, t) {
61
61
  return r.subscribe(() => {
62
- t = !0, s !== void 0 && (E(), queueMicrotask(() => {
63
- p(), e.set(s);
64
- }));
62
+ s = !0, t !== void 0 && e.set(t);
65
63
  }), e;
66
64
  },
67
- disableOn(r, s) {
65
+ disableOn(r, t) {
68
66
  return r.subscribe(() => {
69
- t = !1, s !== void 0 && (E(), queueMicrotask(() => {
70
- p(), e.set(s);
71
- }));
67
+ s = !1, t !== void 0 && e.set(t);
72
68
  }), e;
73
69
  }
74
70
  };
75
71
  return e;
76
- }, h = function() {
72
+ }, i = function() {
77
73
  return {
78
74
  afterAll: [],
79
75
  beforeAll: [],
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 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;
82
+ }).finally(() => {
83
+ s.beforeAll.forEach((r) => r(...e)), s.other.forEach((r) => r(...e)), s.afterAll.forEach((r) => r(...e));
84
+ });
94
85
  };
95
86
  return f.onBefore = (e, r) => {
96
87
  switch (r) {
@@ -128,23 +119,24 @@ const E = () => d += 1, p = () => {
128
119
  }, f.onFinally = (e, r) => {
129
120
  switch (r) {
130
121
  case "beforeAll":
131
- t.beforeAll.push(e);
122
+ s.beforeAll.push(e);
132
123
  break;
133
124
  case "afterAll":
134
- t.afterAll.push(e);
125
+ s.afterAll.push(e);
135
126
  break;
136
127
  default:
137
- t.other.push(e);
128
+ s.other.push(e);
138
129
  }
139
130
  }, f;
140
- }, S = function(o, n, c = !0) {
141
- console.log("Combine", o, n, c);
131
+ }, y = function(o, n, c = !0) {
142
132
  let l = n(o);
143
- const t = [];
133
+ const s = /* @__PURE__ */ new Set();
144
134
  o.forEach((e) => {
145
135
  e.subscribe(() => {
146
- i(c, () => {
147
- l = n(o), t.forEach((r) => r(l));
136
+ a(c, () => {
137
+ d(f, () => {
138
+ l = n(o), s.forEach((r) => r(l));
139
+ });
148
140
  });
149
141
  });
150
142
  });
@@ -159,10 +151,7 @@ const E = () => d += 1, p = () => {
159
151
  throw new Error("Cannot call 'set' on combined store");
160
152
  },
161
153
  subscribe(e) {
162
- return t.push(e), () => {
163
- const r = t.indexOf(e);
164
- ~r && t.splice(r, 1);
165
- };
154
+ return s.add(e), e(l), () => s.delete(e);
166
155
  },
167
156
  enableOn(e) {
168
157
  return e.subscribe(() => c = !0), f;
@@ -172,31 +161,31 @@ const E = () => d += 1, p = () => {
172
161
  }
173
162
  };
174
163
  return f;
175
- }, x = function(o) {
164
+ }, F = function(o) {
176
165
  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),
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),
178
167
  subscribe: (l) => {
179
168
  n.push(l);
180
169
  }
181
170
  };
182
171
  return c;
183
- }, w = function(o) {
172
+ }, p = function(o) {
184
173
  return () => o;
185
- }, F = function(o) {
186
- const n = k(!1);
174
+ }, x = function(o) {
175
+ const n = C(!1);
187
176
  return o.forEach((c) => {
188
- n.on(c, "onBefore", w(!0)), n.on(c, "onFinally", w(!1));
177
+ n.on(c, "onBefore", p(!0)), n.on(c, "onFinally", p(!1));
189
178
  }), n;
190
- }, O = function() {
179
+ }, L = function() {
191
180
  return (o, { result: n }) => n;
192
181
  };
193
182
  export {
194
- S as combine,
183
+ y as combine,
195
184
  m as effect,
196
- i as enableCheck,
197
- x as marker,
198
- F as pending,
199
- O as result,
200
- k as store,
201
- w as to
185
+ a as enableCheck,
186
+ F as marker,
187
+ x as pending,
188
+ L as result,
189
+ C as store,
190
+ p as to
202
191
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vanyamate/sec",
3
- "version": "0.3.1-batch-beta.1",
3
+ "version": "0.3.1-batch-beta.3",
4
4
  "description": "SEC. Store, Effect, Combine. Tiny state manager",
5
5
  "scripts": {
6
6
  "build": "vite build",