@vanyamate/sec 0.2.6 → 0.3.0

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