@vanyamate/sec 0.3.1-batch-beta.0 → 0.3.1-batch-beta.1

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 m=0,A=[];const E=()=>m+=1,d=()=>{m-=1,w()&&B()},w=()=>m==0,k=o=>{w()?o():A.push(o)},B=()=>{A.forEach(o=>o()),A.length=0},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)))})},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(()=>{d(),e.set(s)}))}),e},disableOn(r,s){return r.subscribe(()=>{t=!1,s!==void 0&&(E(),queueMicrotask(()=>{d(),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{d()}};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},p=function(o){return()=>o},O=function(o){const n=y(!1);return o.forEach(c=>{n.on(c,"onBefore",p(!0)),n.on(c,"onFinally",p(!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=p;
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;
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
- let d = 0, A = [];
1
+ let d = 0, A = /* @__PURE__ */ new Map();
2
2
  const E = () => d += 1, p = () => {
3
3
  d -= 1, B() && C();
4
- }, B = () => d == 0, y = (o) => {
5
- B() ? o() : A.push(o);
4
+ }, B = () => d == 0, y = (o, n) => {
5
+ B() ? o() : A.set(n, o);
6
6
  }, C = () => {
7
- A.forEach((o) => o()), A.length = 0;
7
+ A.forEach((o) => o()), A.clear();
8
8
  }, i = function(o, n) {
9
9
  o && n();
10
10
  }, k = function(o, n = { enabled: !0, instantListenerExecution: !1 }) {
@@ -52,7 +52,7 @@ const E = () => d += 1, p = () => {
52
52
  set(r) {
53
53
  o = r, y(() => {
54
54
  l != o && (l = o, c.forEach((s) => s(o)));
55
- });
55
+ }, this);
56
56
  },
57
57
  subscribe(r) {
58
58
  return c.add(r), f && r(o), () => c.delete(r);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vanyamate/sec",
3
- "version": "0.3.1-batch-beta.0",
3
+ "version": "0.3.1-batch-beta.1",
4
4
  "description": "SEC. Store, Effect, Combine. Tiny state manager",
5
5
  "scripts": {
6
6
  "build": "vite build",