@vanyamate/sec 0.2.7 → 0.3.1-batch-beta.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 +5 -3
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +122 -101
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -161,8 +161,10 @@ const postsIsPending = pending([
|
|
|
161
161
|
|
|
162
162
|
Store stores data and subscribes to effect.
|
|
163
163
|
|
|
164
|
-
When initializing, the store takes 2 values. The first value is the initialization data. The second value is
|
|
165
|
-
|
|
164
|
+
When initializing, the store takes 2 values. The first value is the initialization data. The second value is settings.
|
|
165
|
+
|
|
166
|
+
- `enabled` - default is `true`. When disabled, the store will not be updated.
|
|
167
|
+
- `instantListenerExecution` - default is `false`. When enabled, a listener will instant executed when subscribe.
|
|
166
168
|
|
|
167
169
|
The store has an api.
|
|
168
170
|
|
|
@@ -186,7 +188,7 @@ The store has an api.
|
|
|
186
188
|
|
|
187
189
|
```typescript
|
|
188
190
|
|
|
189
|
-
const authIsPending = store<boolean>(false)
|
|
191
|
+
const authIsPending = store<boolean>(false, { enabled: true, instantListenerExecution: true })
|
|
190
192
|
.on(loginEffect, 'onBefore', () => true)
|
|
191
193
|
.on(loginEffect, 'onFinally', to(false)); // instead of () => false
|
|
192
194
|
|
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"});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;
|
package/dist/index.d.ts
CHANGED
|
@@ -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,77 +1,98 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
let d = 0, A = [];
|
|
2
|
+
const E = () => d += 1, p = () => {
|
|
3
|
+
d -= 1, B() && C();
|
|
4
|
+
}, B = () => d == 0, y = (o) => {
|
|
5
|
+
B() ? o() : A.push(o);
|
|
6
|
+
}, C = () => {
|
|
7
|
+
A.forEach((o) => o()), A.length = 0;
|
|
8
|
+
}, i = function(o, n) {
|
|
9
|
+
o && n();
|
|
10
|
+
}, k = function(o, n = { enabled: !0, instantListenerExecution: !1 }) {
|
|
11
|
+
const c = /* @__PURE__ */ new Set();
|
|
12
|
+
let l, { enabled: t = !0, instantListenerExecution: f = !1 } = n;
|
|
13
|
+
const e = {
|
|
14
|
+
on: (r, s, a) => (s === "onBefore" ? r.onBefore(
|
|
15
|
+
(...u) => i(
|
|
16
|
+
t,
|
|
17
|
+
() => e.set(
|
|
18
|
+
a(o, { args: u })
|
|
10
19
|
)
|
|
11
20
|
)
|
|
12
|
-
) :
|
|
13
|
-
(
|
|
14
|
-
|
|
15
|
-
() =>
|
|
16
|
-
|
|
17
|
-
result:
|
|
18
|
-
args:
|
|
21
|
+
) : s === "onSuccess" ? r.onSuccess(
|
|
22
|
+
(u, ...b) => i(
|
|
23
|
+
t,
|
|
24
|
+
() => e.set(
|
|
25
|
+
a(o, {
|
|
26
|
+
result: u,
|
|
27
|
+
args: b
|
|
19
28
|
})
|
|
20
29
|
)
|
|
21
30
|
)
|
|
22
|
-
) :
|
|
23
|
-
(
|
|
24
|
-
|
|
25
|
-
() =>
|
|
26
|
-
|
|
27
|
-
error:
|
|
28
|
-
args:
|
|
31
|
+
) : s === "onError" ? r.onError(
|
|
32
|
+
(u, ...b) => i(
|
|
33
|
+
t,
|
|
34
|
+
() => e.set(
|
|
35
|
+
a(o, {
|
|
36
|
+
error: u,
|
|
37
|
+
args: b
|
|
29
38
|
})
|
|
30
39
|
)
|
|
31
40
|
)
|
|
32
|
-
) :
|
|
33
|
-
(...
|
|
34
|
-
|
|
35
|
-
() =>
|
|
36
|
-
|
|
41
|
+
) : r.onFinally(
|
|
42
|
+
(...u) => i(
|
|
43
|
+
t,
|
|
44
|
+
() => e.set(
|
|
45
|
+
a(o, { args: u })
|
|
37
46
|
)
|
|
38
47
|
)
|
|
39
|
-
),
|
|
48
|
+
), e),
|
|
40
49
|
get() {
|
|
41
|
-
return
|
|
50
|
+
return o;
|
|
42
51
|
},
|
|
43
|
-
set(
|
|
44
|
-
|
|
52
|
+
set(r) {
|
|
53
|
+
o = r, y(() => {
|
|
54
|
+
l != o && (l = o, c.forEach((s) => s(o)));
|
|
55
|
+
});
|
|
45
56
|
},
|
|
46
|
-
subscribe(
|
|
47
|
-
return
|
|
48
|
-
const o = f.indexOf(s);
|
|
49
|
-
~o && f.splice(o, 1);
|
|
50
|
-
};
|
|
57
|
+
subscribe(r) {
|
|
58
|
+
return c.add(r), f && r(o), () => c.delete(r);
|
|
51
59
|
},
|
|
52
|
-
enableOn(
|
|
53
|
-
return
|
|
60
|
+
enableOn(r, s) {
|
|
61
|
+
return r.subscribe(() => {
|
|
62
|
+
t = !0, s !== void 0 && (E(), queueMicrotask(() => {
|
|
63
|
+
p(), e.set(s);
|
|
64
|
+
}));
|
|
65
|
+
}), e;
|
|
54
66
|
},
|
|
55
|
-
disableOn(
|
|
56
|
-
return
|
|
67
|
+
disableOn(r, s) {
|
|
68
|
+
return r.subscribe(() => {
|
|
69
|
+
t = !1, s !== void 0 && (E(), queueMicrotask(() => {
|
|
70
|
+
p(), e.set(s);
|
|
71
|
+
}));
|
|
72
|
+
}), e;
|
|
57
73
|
}
|
|
58
74
|
};
|
|
59
|
-
return
|
|
60
|
-
},
|
|
75
|
+
return e;
|
|
76
|
+
}, h = function() {
|
|
61
77
|
return {
|
|
62
78
|
afterAll: [],
|
|
63
79
|
beforeAll: [],
|
|
64
80
|
other: []
|
|
65
81
|
};
|
|
66
|
-
},
|
|
67
|
-
const n =
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
82
|
+
}, 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
|
+
}
|
|
73
94
|
};
|
|
74
|
-
return
|
|
95
|
+
return f.onBefore = (e, r) => {
|
|
75
96
|
switch (r) {
|
|
76
97
|
case "beforeAll":
|
|
77
98
|
n.beforeAll.push(e);
|
|
@@ -82,100 +103,100 @@ const u = function(c, n) {
|
|
|
82
103
|
default:
|
|
83
104
|
n.other.push(e);
|
|
84
105
|
}
|
|
85
|
-
},
|
|
106
|
+
}, f.onSuccess = (e, r) => {
|
|
86
107
|
switch (r) {
|
|
87
108
|
case "beforeAll":
|
|
88
|
-
|
|
109
|
+
c.beforeAll.push(e);
|
|
89
110
|
break;
|
|
90
111
|
case "afterAll":
|
|
91
|
-
|
|
112
|
+
c.afterAll.push(e);
|
|
92
113
|
break;
|
|
93
114
|
default:
|
|
94
|
-
|
|
115
|
+
c.other.push(e);
|
|
95
116
|
}
|
|
96
|
-
},
|
|
117
|
+
}, f.onError = (e, r) => {
|
|
97
118
|
switch (r) {
|
|
98
119
|
case "beforeAll":
|
|
99
|
-
|
|
120
|
+
l.beforeAll.push(e);
|
|
100
121
|
break;
|
|
101
122
|
case "afterAll":
|
|
102
|
-
|
|
123
|
+
l.afterAll.push(e);
|
|
103
124
|
break;
|
|
104
125
|
default:
|
|
105
|
-
|
|
126
|
+
l.other.push(e);
|
|
106
127
|
}
|
|
107
|
-
},
|
|
128
|
+
}, f.onFinally = (e, r) => {
|
|
108
129
|
switch (r) {
|
|
109
130
|
case "beforeAll":
|
|
110
|
-
|
|
131
|
+
t.beforeAll.push(e);
|
|
111
132
|
break;
|
|
112
133
|
case "afterAll":
|
|
113
|
-
|
|
134
|
+
t.afterAll.push(e);
|
|
114
135
|
break;
|
|
115
136
|
default:
|
|
116
|
-
|
|
137
|
+
t.other.push(e);
|
|
117
138
|
}
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
console.log("Combine",
|
|
121
|
-
let
|
|
122
|
-
const
|
|
123
|
-
|
|
139
|
+
}, f;
|
|
140
|
+
}, S = function(o, n, c = !0) {
|
|
141
|
+
console.log("Combine", o, n, c);
|
|
142
|
+
let l = n(o);
|
|
143
|
+
const t = [];
|
|
144
|
+
o.forEach((e) => {
|
|
124
145
|
e.subscribe(() => {
|
|
125
|
-
|
|
126
|
-
|
|
146
|
+
i(c, () => {
|
|
147
|
+
l = n(o), t.forEach((r) => r(l));
|
|
127
148
|
});
|
|
128
149
|
});
|
|
129
150
|
});
|
|
130
|
-
const
|
|
151
|
+
const f = {
|
|
131
152
|
on: () => {
|
|
132
153
|
throw new Error("Cannot call 'on' on combined store");
|
|
133
154
|
},
|
|
134
155
|
get() {
|
|
135
|
-
return
|
|
156
|
+
return l;
|
|
136
157
|
},
|
|
137
158
|
set() {
|
|
138
159
|
throw new Error("Cannot call 'set' on combined store");
|
|
139
160
|
},
|
|
140
161
|
subscribe(e) {
|
|
141
|
-
return
|
|
142
|
-
const r =
|
|
143
|
-
~r &&
|
|
162
|
+
return t.push(e), () => {
|
|
163
|
+
const r = t.indexOf(e);
|
|
164
|
+
~r && t.splice(r, 1);
|
|
144
165
|
};
|
|
145
166
|
},
|
|
146
167
|
enableOn(e) {
|
|
147
|
-
return e.subscribe(() =>
|
|
168
|
+
return e.subscribe(() => c = !0), f;
|
|
148
169
|
},
|
|
149
170
|
disableOn(e) {
|
|
150
|
-
return e.subscribe(() =>
|
|
171
|
+
return e.subscribe(() => c = !1), f;
|
|
151
172
|
}
|
|
152
173
|
};
|
|
153
|
-
return
|
|
154
|
-
},
|
|
155
|
-
const n = [],
|
|
156
|
-
on: (
|
|
157
|
-
subscribe: (
|
|
158
|
-
n.push(
|
|
174
|
+
return f;
|
|
175
|
+
}, x = function(o) {
|
|
176
|
+
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),
|
|
178
|
+
subscribe: (l) => {
|
|
179
|
+
n.push(l);
|
|
159
180
|
}
|
|
160
181
|
};
|
|
161
|
-
return
|
|
162
|
-
},
|
|
163
|
-
return () =>
|
|
164
|
-
},
|
|
165
|
-
const n =
|
|
166
|
-
return
|
|
167
|
-
n.on(
|
|
182
|
+
return c;
|
|
183
|
+
}, w = function(o) {
|
|
184
|
+
return () => o;
|
|
185
|
+
}, F = function(o) {
|
|
186
|
+
const n = k(!1);
|
|
187
|
+
return o.forEach((c) => {
|
|
188
|
+
n.on(c, "onBefore", w(!0)), n.on(c, "onFinally", w(!1));
|
|
168
189
|
}), n;
|
|
169
|
-
},
|
|
170
|
-
return (
|
|
190
|
+
}, O = function() {
|
|
191
|
+
return (o, { result: n }) => n;
|
|
171
192
|
};
|
|
172
193
|
export {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
194
|
+
S as combine,
|
|
195
|
+
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
|
|
181
202
|
};
|