@vanyamate/sec 0.3.0 → 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.js +120 -98
- 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.js
CHANGED
|
@@ -1,180 +1,202 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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(
|
|
8
15
|
(...u) => i(
|
|
9
|
-
|
|
10
|
-
() =>
|
|
11
|
-
|
|
16
|
+
t,
|
|
17
|
+
() => e.set(
|
|
18
|
+
a(o, { args: u })
|
|
12
19
|
)
|
|
13
20
|
)
|
|
14
|
-
) :
|
|
15
|
-
(u, ...
|
|
16
|
-
|
|
17
|
-
() =>
|
|
18
|
-
|
|
21
|
+
) : s === "onSuccess" ? r.onSuccess(
|
|
22
|
+
(u, ...b) => i(
|
|
23
|
+
t,
|
|
24
|
+
() => e.set(
|
|
25
|
+
a(o, {
|
|
19
26
|
result: u,
|
|
20
|
-
args:
|
|
27
|
+
args: b
|
|
21
28
|
})
|
|
22
29
|
)
|
|
23
30
|
)
|
|
24
|
-
) :
|
|
25
|
-
(u, ...
|
|
26
|
-
|
|
27
|
-
() =>
|
|
28
|
-
|
|
31
|
+
) : s === "onError" ? r.onError(
|
|
32
|
+
(u, ...b) => i(
|
|
33
|
+
t,
|
|
34
|
+
() => e.set(
|
|
35
|
+
a(o, {
|
|
29
36
|
error: u,
|
|
30
|
-
args:
|
|
37
|
+
args: b
|
|
31
38
|
})
|
|
32
39
|
)
|
|
33
40
|
)
|
|
34
|
-
) :
|
|
41
|
+
) : r.onFinally(
|
|
35
42
|
(...u) => i(
|
|
36
|
-
|
|
37
|
-
() =>
|
|
38
|
-
|
|
43
|
+
t,
|
|
44
|
+
() => e.set(
|
|
45
|
+
a(o, { args: u })
|
|
39
46
|
)
|
|
40
47
|
)
|
|
41
|
-
),
|
|
48
|
+
), e),
|
|
42
49
|
get() {
|
|
43
|
-
return
|
|
50
|
+
return o;
|
|
44
51
|
},
|
|
45
|
-
set(
|
|
46
|
-
|
|
52
|
+
set(r) {
|
|
53
|
+
o = r, y(() => {
|
|
54
|
+
l != o && (l = o, c.forEach((s) => s(o)));
|
|
55
|
+
});
|
|
47
56
|
},
|
|
48
|
-
subscribe(
|
|
49
|
-
return
|
|
57
|
+
subscribe(r) {
|
|
58
|
+
return c.add(r), f && r(o), () => c.delete(r);
|
|
50
59
|
},
|
|
51
|
-
enableOn(
|
|
52
|
-
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;
|
|
53
66
|
},
|
|
54
|
-
disableOn(
|
|
55
|
-
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;
|
|
56
73
|
}
|
|
57
74
|
};
|
|
58
|
-
return
|
|
75
|
+
return e;
|
|
59
76
|
}, h = function() {
|
|
60
77
|
return {
|
|
61
78
|
afterAll: [],
|
|
62
79
|
beforeAll: [],
|
|
63
80
|
other: []
|
|
64
81
|
};
|
|
65
|
-
},
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
+
}
|
|
72
94
|
};
|
|
73
|
-
return
|
|
95
|
+
return f.onBefore = (e, r) => {
|
|
74
96
|
switch (r) {
|
|
75
97
|
case "beforeAll":
|
|
76
|
-
|
|
98
|
+
n.beforeAll.push(e);
|
|
77
99
|
break;
|
|
78
100
|
case "afterAll":
|
|
79
|
-
|
|
101
|
+
n.afterAll.push(e);
|
|
80
102
|
break;
|
|
81
103
|
default:
|
|
82
|
-
|
|
104
|
+
n.other.push(e);
|
|
83
105
|
}
|
|
84
|
-
},
|
|
106
|
+
}, f.onSuccess = (e, r) => {
|
|
85
107
|
switch (r) {
|
|
86
108
|
case "beforeAll":
|
|
87
|
-
|
|
109
|
+
c.beforeAll.push(e);
|
|
88
110
|
break;
|
|
89
111
|
case "afterAll":
|
|
90
|
-
|
|
112
|
+
c.afterAll.push(e);
|
|
91
113
|
break;
|
|
92
114
|
default:
|
|
93
|
-
|
|
115
|
+
c.other.push(e);
|
|
94
116
|
}
|
|
95
|
-
},
|
|
117
|
+
}, f.onError = (e, r) => {
|
|
96
118
|
switch (r) {
|
|
97
119
|
case "beforeAll":
|
|
98
|
-
|
|
120
|
+
l.beforeAll.push(e);
|
|
99
121
|
break;
|
|
100
122
|
case "afterAll":
|
|
101
|
-
|
|
123
|
+
l.afterAll.push(e);
|
|
102
124
|
break;
|
|
103
125
|
default:
|
|
104
|
-
|
|
126
|
+
l.other.push(e);
|
|
105
127
|
}
|
|
106
|
-
},
|
|
128
|
+
}, f.onFinally = (e, r) => {
|
|
107
129
|
switch (r) {
|
|
108
130
|
case "beforeAll":
|
|
109
|
-
|
|
131
|
+
t.beforeAll.push(e);
|
|
110
132
|
break;
|
|
111
133
|
case "afterAll":
|
|
112
|
-
|
|
134
|
+
t.afterAll.push(e);
|
|
113
135
|
break;
|
|
114
136
|
default:
|
|
115
|
-
|
|
137
|
+
t.other.push(e);
|
|
116
138
|
}
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
console.log("Combine",
|
|
120
|
-
let
|
|
121
|
-
const
|
|
122
|
-
|
|
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) => {
|
|
123
145
|
e.subscribe(() => {
|
|
124
|
-
i(
|
|
125
|
-
|
|
146
|
+
i(c, () => {
|
|
147
|
+
l = n(o), t.forEach((r) => r(l));
|
|
126
148
|
});
|
|
127
149
|
});
|
|
128
150
|
});
|
|
129
|
-
const
|
|
151
|
+
const f = {
|
|
130
152
|
on: () => {
|
|
131
153
|
throw new Error("Cannot call 'on' on combined store");
|
|
132
154
|
},
|
|
133
155
|
get() {
|
|
134
|
-
return
|
|
156
|
+
return l;
|
|
135
157
|
},
|
|
136
158
|
set() {
|
|
137
159
|
throw new Error("Cannot call 'set' on combined store");
|
|
138
160
|
},
|
|
139
161
|
subscribe(e) {
|
|
140
|
-
return
|
|
141
|
-
const r =
|
|
142
|
-
~r &&
|
|
162
|
+
return t.push(e), () => {
|
|
163
|
+
const r = t.indexOf(e);
|
|
164
|
+
~r && t.splice(r, 1);
|
|
143
165
|
};
|
|
144
166
|
},
|
|
145
167
|
enableOn(e) {
|
|
146
|
-
return e.subscribe(() =>
|
|
168
|
+
return e.subscribe(() => c = !0), f;
|
|
147
169
|
},
|
|
148
170
|
disableOn(e) {
|
|
149
|
-
return e.subscribe(() =>
|
|
171
|
+
return e.subscribe(() => c = !1), f;
|
|
150
172
|
}
|
|
151
173
|
};
|
|
152
|
-
return
|
|
153
|
-
},
|
|
154
|
-
const
|
|
155
|
-
on: (
|
|
156
|
-
subscribe: (
|
|
157
|
-
|
|
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);
|
|
158
180
|
}
|
|
159
181
|
};
|
|
160
|
-
return
|
|
161
|
-
},
|
|
162
|
-
return () =>
|
|
163
|
-
},
|
|
164
|
-
const
|
|
165
|
-
return
|
|
166
|
-
|
|
167
|
-
}),
|
|
168
|
-
},
|
|
169
|
-
return (
|
|
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));
|
|
189
|
+
}), n;
|
|
190
|
+
}, O = function() {
|
|
191
|
+
return (o, { result: n }) => n;
|
|
170
192
|
};
|
|
171
193
|
export {
|
|
172
|
-
|
|
173
|
-
|
|
194
|
+
S as combine,
|
|
195
|
+
m as effect,
|
|
174
196
|
i as enableCheck,
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
197
|
+
x as marker,
|
|
198
|
+
F as pending,
|
|
199
|
+
O as result,
|
|
200
|
+
k as store,
|
|
201
|
+
w as to
|
|
180
202
|
};
|