@vanyamate/sec 0.3.1-batch-beta.7 → 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()&&B()},m=()=>d===0,p=(o,t)=>{S(),E.set(o,t),queueMicrotask(k)},B=()=>{E.forEach(o=>o()),E.clear()},i=function(o,t){o&&t()},w=function(o,t={enabled:!0,instantListenerExecution:!1}){const f=new Set;let s=o,{enabled:c=!0,instantListenerExecution:l=!1}=t;const r={on:(e,n,u)=>(n==="onBefore"?e.onBefore((...a)=>i(c,()=>r.set(u(o,{args:a})))):n==="onSuccess"?e.onSuccess((a,...b)=>i(c,()=>r.set(u(o,{result:a,args:b})))):n==="onError"?e.onError((a,...b)=>i(c,()=>r.set(u(o,{error:a,args:b})))):e.onFinally((...a)=>i(c,()=>r.set(u(o,{args:a})))),r),get(){return o},set(e){o=e,p(this,()=>{s!==o&&(s=o,f.forEach(n=>n(o)))})},subscribe(e){return f.add(e),l&&e(o),()=>f.delete(e)},enableOn(e,n){return e.subscribe(()=>{c=!0,n!==void 0&&r.set(n)}),r},disableOn(e,n){return e.subscribe(()=>{c=!1,n!==void 0&&r.set(n)}),r}};return r},h=function(){return{afterAll:[],beforeAll:[],other:[]}},y=function(o){const t=h(),f=h(),s=h(),c=h(),l=async function(...r){return t.beforeAll.forEach(e=>e(...r)),t.other.forEach(e=>e(...r)),t.afterAll.forEach(e=>e(...r)),o(...r).then(e=>(f.beforeAll.forEach(n=>n(e,...r)),f.other.forEach(n=>n(e,...r)),f.afterAll.forEach(n=>n(e,...r)),e)).catch(e=>{throw s.beforeAll.forEach(n=>n(e,...r)),s.other.forEach(n=>n(e,...r)),s.afterAll.forEach(n=>n(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":t.beforeAll.push(r);break;case"afterAll":t.afterAll.push(r);break;default:t.other.push(r)}},l.onSuccess=(r,e)=>{switch(e){case"beforeAll":f.beforeAll.push(r);break;case"afterAll":f.afterAll.push(r);break;default:f.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,t,f={enabled:!0,instantListenerExecution:!1}){let s,c;s=c=t(o);const l=new Set;let{enabled:r=!0,instantListenerExecution:e=!1}=f;o.forEach(u=>{u.subscribe(()=>{i(r,()=>{p(n,()=>{s=t(o),s!==c&&(c=s,l.forEach(a=>a(s)))})})})});const n={on:()=>{throw new Error("Cannot call 'on' on combined store")},get(){return s},set(){throw new Error("Cannot call 'set' on combined store")},subscribe(u){return l.add(u),e&&u(s),()=>l.delete(u)},enableOn(u){return u.subscribe(()=>r=!0),n},disableOn(u){return u.subscribe(()=>r=!1),n}};return n},F=function(o){const t=[],f={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),f),subscribe:s=>{t.push(s)}};return f},A=function(o){return()=>o},L=function(o){const t=w(!1);return o.forEach(f=>{t.on(f,"onBefore",A(!0)),t.on(f,"onFinally",A(!1))}),t},x=function(){return(o,{result:t})=>t};exports.combine=C;exports.effect=y;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
@@ -49,7 +49,7 @@ export declare type Store<State> = {
49
49
  disableOn: StoreMarkerSubscribe<State>;
50
50
  get: () => State;
51
51
  set: (data: State) => void;
52
- subscribe: (listener: StoreListener<State>) => () => void;
52
+ subscribe: (listener: StoreListener<State>, instantExecute?: boolean) => () => void;
53
53
  };
54
54
 
55
55
  export declare const store: <State extends any>(state: State, options?: StoreOptions) => Store<State>;
package/dist/index.js CHANGED
@@ -7,22 +7,22 @@ const w = () => A += 1, B = () => {
7
7
  E.forEach((o) => o()), E.clear();
8
8
  }, i = function(o, t) {
9
9
  o && t();
10
- }, C = function(o, t = { enabled: !0, instantListenerExecution: !1 }) {
11
- const f = /* @__PURE__ */ new Set();
12
- let s = o, { enabled: c = !0, instantListenerExecution: l = !1 } = 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
13
  const r = {
14
- on: (e, n, u) => (n === "onBefore" ? e.onBefore(
14
+ on: (e, n, f) => (n === "onBefore" ? e.onBefore(
15
15
  (...a) => i(
16
16
  c,
17
17
  () => r.set(
18
- u(o, { args: a })
18
+ f(o, { args: a })
19
19
  )
20
20
  )
21
21
  ) : n === "onSuccess" ? e.onSuccess(
22
22
  (a, ...b) => i(
23
23
  c,
24
24
  () => r.set(
25
- u(o, {
25
+ f(o, {
26
26
  result: a,
27
27
  args: b
28
28
  })
@@ -32,7 +32,7 @@ const w = () => A += 1, B = () => {
32
32
  (a, ...b) => i(
33
33
  c,
34
34
  () => r.set(
35
- u(o, {
35
+ f(o, {
36
36
  error: a,
37
37
  args: b
38
38
  })
@@ -42,7 +42,7 @@ const w = () => A += 1, B = () => {
42
42
  (...a) => i(
43
43
  c,
44
44
  () => r.set(
45
- u(o, { args: a })
45
+ f(o, { args: a })
46
46
  )
47
47
  )
48
48
  ), r),
@@ -51,11 +51,11 @@ const w = () => A += 1, B = () => {
51
51
  },
52
52
  set(e) {
53
53
  o = e, p(this, () => {
54
- s !== o && (s = o, f.forEach((n) => n(o)));
54
+ s !== o && (s = o, u.forEach((n) => n(o)));
55
55
  });
56
56
  },
57
- subscribe(e) {
58
- return f.add(e), l && e(o), () => f.delete(e);
57
+ subscribe(e, n = !0) {
58
+ return u.add(e), n && l && e(o), () => u.delete(e);
59
59
  },
60
60
  enableOn(e, n) {
61
61
  return e.subscribe(() => {
@@ -76,8 +76,8 @@ const w = () => A += 1, B = () => {
76
76
  other: []
77
77
  };
78
78
  }, m = function(o) {
79
- const t = h(), f = 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) => (f.beforeAll.forEach((n) => n(e, ...r)), f.other.forEach((n) => n(e, ...r)), f.afterAll.forEach((n) => n(e, ...r)), e)).catch((e) => {
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
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
83
  c.beforeAll.forEach((e) => e(...r)), c.other.forEach((e) => e(...r)), c.afterAll.forEach((e) => e(...r));
@@ -97,13 +97,13 @@ const w = () => A += 1, B = () => {
97
97
  }, l.onSuccess = (r, e) => {
98
98
  switch (e) {
99
99
  case "beforeAll":
100
- f.beforeAll.push(r);
100
+ u.beforeAll.push(r);
101
101
  break;
102
102
  case "afterAll":
103
- f.afterAll.push(r);
103
+ u.afterAll.push(r);
104
104
  break;
105
105
  default:
106
- f.other.push(r);
106
+ u.other.push(r);
107
107
  }
108
108
  }, l.onError = (r, e) => {
109
109
  switch (e) {
@@ -128,19 +128,19 @@ const w = () => A += 1, B = () => {
128
128
  c.other.push(r);
129
129
  }
130
130
  }, l;
131
- }, y = function(o, t, f = { enabled: !0, instantListenerExecution: !1 }) {
131
+ }, y = function(o, t, u = { enabled: !0, instantListenerExecution: !0 }) {
132
132
  let s, c;
133
133
  s = c = t(o);
134
134
  const l = /* @__PURE__ */ new Set();
135
- let { enabled: r = !0, instantListenerExecution: e = !1 } = f;
136
- o.forEach((u) => {
137
- u.subscribe(() => {
135
+ let { enabled: r = !0, instantListenerExecution: e = !0 } = u;
136
+ o.forEach((f) => {
137
+ f.subscribe(() => {
138
138
  i(r, () => {
139
139
  p(n, () => {
140
140
  s = t(o), s !== c && (c = s, l.forEach((a) => a(s)));
141
141
  });
142
142
  });
143
- });
143
+ }, !1);
144
144
  });
145
145
  const n = {
146
146
  on: () => {
@@ -152,31 +152,31 @@ const w = () => A += 1, B = () => {
152
152
  set() {
153
153
  throw new Error("Cannot call 'set' on combined store");
154
154
  },
155
- subscribe(u) {
156
- return l.add(u), e && u(s), () => l.delete(u);
155
+ subscribe(f, a = !0) {
156
+ return l.add(f), a && e && f(s), () => l.delete(f);
157
157
  },
158
- enableOn(u) {
159
- return u.subscribe(() => r = !0), n;
158
+ enableOn(f) {
159
+ return f.subscribe(() => r = !0), n;
160
160
  },
161
- disableOn(u) {
162
- return u.subscribe(() => r = !1), n;
161
+ disableOn(f) {
162
+ return f.subscribe(() => r = !1), n;
163
163
  }
164
164
  };
165
165
  return n;
166
166
  }, x = function(o) {
167
- const t = [], f = {
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), f),
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
170
  t.push(s);
171
171
  }
172
172
  };
173
- return f;
173
+ return u;
174
174
  }, d = function(o) {
175
175
  return () => o;
176
176
  }, F = function(o) {
177
177
  const t = C(!1);
178
- return o.forEach((f) => {
179
- t.on(f, "onBefore", d(!0)), t.on(f, "onFinally", d(!1));
178
+ return o.forEach((u) => {
179
+ t.on(u, "onBefore", d(!0)), t.on(u, "onFinally", d(!1));
180
180
  }), t;
181
181
  }, L = function() {
182
182
  return (o, { result: t }) => t;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vanyamate/sec",
3
- "version": "0.3.1-batch-beta.7",
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",