@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 +3 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +7 -2
- package/dist/index.js +95 -96
- package/package.json +1 -1
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
|
|
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
|
|
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,
|
|
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
|
|
2
|
-
|
|
3
|
-
},
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
) :
|
|
13
|
-
(
|
|
14
|
-
|
|
15
|
-
() =>
|
|
16
|
-
|
|
17
|
-
result:
|
|
18
|
-
args:
|
|
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
|
-
) :
|
|
23
|
-
(
|
|
24
|
-
|
|
25
|
-
() =>
|
|
26
|
-
|
|
27
|
-
error:
|
|
28
|
-
args:
|
|
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
|
-
) :
|
|
33
|
-
(...
|
|
34
|
-
|
|
35
|
-
() =>
|
|
36
|
-
|
|
34
|
+
) : e.onFinally(
|
|
35
|
+
(...u) => i(
|
|
36
|
+
s,
|
|
37
|
+
() => o.set(
|
|
38
|
+
f(n, { args: u })
|
|
37
39
|
)
|
|
38
40
|
)
|
|
39
|
-
),
|
|
41
|
+
), o),
|
|
40
42
|
get() {
|
|
41
|
-
return
|
|
43
|
+
return n;
|
|
42
44
|
},
|
|
43
|
-
set(
|
|
44
|
-
|
|
45
|
+
set(e) {
|
|
46
|
+
n = e, l.forEach((r) => r(n));
|
|
45
47
|
},
|
|
46
|
-
subscribe(
|
|
47
|
-
return
|
|
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(
|
|
53
|
-
return
|
|
51
|
+
enableOn(e, r) {
|
|
52
|
+
return e.subscribe(() => s = !0), r !== void 0 && o.set(r), o;
|
|
54
53
|
},
|
|
55
|
-
disableOn(
|
|
56
|
-
return
|
|
54
|
+
disableOn(e, r) {
|
|
55
|
+
return e.subscribe(() => s = !1), r !== void 0 && o.set(r), o;
|
|
57
56
|
}
|
|
58
57
|
};
|
|
59
|
-
return
|
|
60
|
-
},
|
|
58
|
+
return o;
|
|
59
|
+
}, h = function() {
|
|
61
60
|
return {
|
|
62
61
|
afterAll: [],
|
|
63
62
|
beforeAll: [],
|
|
64
63
|
other: []
|
|
65
64
|
};
|
|
66
|
-
},
|
|
67
|
-
const
|
|
68
|
-
return
|
|
69
|
-
throw
|
|
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
|
-
|
|
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
|
-
|
|
76
|
+
t.beforeAll.push(e);
|
|
78
77
|
break;
|
|
79
78
|
case "afterAll":
|
|
80
|
-
|
|
79
|
+
t.afterAll.push(e);
|
|
81
80
|
break;
|
|
82
81
|
default:
|
|
83
|
-
|
|
82
|
+
t.other.push(e);
|
|
84
83
|
}
|
|
85
84
|
}, o.onSuccess = (e, r) => {
|
|
86
85
|
switch (r) {
|
|
87
86
|
case "beforeAll":
|
|
88
|
-
|
|
87
|
+
l.beforeAll.push(e);
|
|
89
88
|
break;
|
|
90
89
|
case "afterAll":
|
|
91
|
-
|
|
90
|
+
l.afterAll.push(e);
|
|
92
91
|
break;
|
|
93
92
|
default:
|
|
94
|
-
|
|
93
|
+
l.other.push(e);
|
|
95
94
|
}
|
|
96
95
|
}, o.onError = (e, r) => {
|
|
97
96
|
switch (r) {
|
|
98
97
|
case "beforeAll":
|
|
99
|
-
|
|
98
|
+
s.beforeAll.push(e);
|
|
100
99
|
break;
|
|
101
100
|
case "afterAll":
|
|
102
|
-
|
|
101
|
+
s.afterAll.push(e);
|
|
103
102
|
break;
|
|
104
103
|
default:
|
|
105
|
-
|
|
104
|
+
s.other.push(e);
|
|
106
105
|
}
|
|
107
106
|
}, o.onFinally = (e, r) => {
|
|
108
107
|
switch (r) {
|
|
109
108
|
case "beforeAll":
|
|
110
|
-
|
|
109
|
+
c.beforeAll.push(e);
|
|
111
110
|
break;
|
|
112
111
|
case "afterAll":
|
|
113
|
-
|
|
112
|
+
c.afterAll.push(e);
|
|
114
113
|
break;
|
|
115
114
|
default:
|
|
116
|
-
|
|
115
|
+
c.other.push(e);
|
|
117
116
|
}
|
|
118
117
|
}, o;
|
|
119
|
-
},
|
|
120
|
-
console.log("Combine",
|
|
121
|
-
let
|
|
122
|
-
const
|
|
123
|
-
|
|
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
|
-
|
|
126
|
-
|
|
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
|
|
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
|
|
142
|
-
const r =
|
|
143
|
-
~r &&
|
|
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(() =>
|
|
146
|
+
return e.subscribe(() => l = !0), o;
|
|
148
147
|
},
|
|
149
148
|
disableOn(e) {
|
|
150
|
-
return e.subscribe(() =>
|
|
149
|
+
return e.subscribe(() => l = !1), o;
|
|
151
150
|
}
|
|
152
151
|
};
|
|
153
152
|
return o;
|
|
154
|
-
},
|
|
155
|
-
const
|
|
156
|
-
on: (
|
|
157
|
-
subscribe: (
|
|
158
|
-
|
|
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
|
|
162
|
-
},
|
|
163
|
-
return () =>
|
|
164
|
-
},
|
|
165
|
-
const
|
|
166
|
-
return
|
|
167
|
-
|
|
168
|
-
}),
|
|
169
|
-
},
|
|
170
|
-
return (
|
|
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
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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
|
};
|