@vanyamate/sec 0.2.1 → 0.2.2
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 +1 -1
- package/dist/index.js +95 -87
- package/package.json +1 -1
- package/src/store/index.ts +16 -7
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=function(
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=function(o,c){o&&c()},b=function(o,c=!0){const f=[],t={on:(n,s,e)=>(s==="onBefore"?n.onBefore((...r)=>u(c,()=>{o=e(o,{args:r}),f.forEach(l=>l(o))})):s==="onSuccess"?n.onSuccess((r,...l)=>u(c,()=>{o=e(o,{result:r,args:l}),f.forEach(i=>i(o))})):s==="onError"?n.onError((r,...l)=>u(c,()=>{o=e(o,{error:r,args:l}),f.forEach(i=>i(o))})):n.onFinally((...r)=>u(c,()=>o=e(o,{args:r}))),t),get(){return o},set(n){o=n},subscribe(n){return f.push(n),()=>{const s=f.indexOf(n);~s&&f.splice(s,1)}},enableOn(n){return n.subscribe(()=>c=!0),t},disableOn(n){return n.subscribe(()=>c=!1),t}};return t},h=function(){return{afterAll:[],beforeAll:[],other:[]}},A=function(o){const c=h(),f=h(),t=h(),n=h(),s=async function(...e){return c.beforeAll.forEach(r=>r(...e)),c.other.forEach(r=>r(...e)),c.afterAll.forEach(r=>r(...e)),o(...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 t.beforeAll.forEach(l=>l(r,...e)),t.other.forEach(l=>l(r,...e)),t.afterAll.forEach(l=>l(r,...e)),r}).finally(()=>{n.beforeAll.forEach(r=>r(...e)),n.other.forEach(r=>r(...e)),n.afterAll.forEach(r=>r(...e))})};return s.onBefore=(e,r)=>{switch(r){case"beforeAll":c.beforeAll.push(e);break;case"afterAll":c.afterAll.push(e);break;default:c.other.push(e)}},s.onSuccess=(e,r)=>{switch(r){case"beforeAll":f.beforeAll.push(e);break;case"afterAll":f.afterAll.push(e);break;default:f.other.push(e)}},s.onError=(e,r)=>{switch(r){case"beforeAll":t.beforeAll.push(e);break;case"afterAll":t.afterAll.push(e);break;default:t.other.push(e)}},s.onFinally=(e,r)=>{switch(r){case"beforeAll":n.beforeAll.push(e);break;case"afterAll":n.afterAll.push(e);break;default:n.other.push(e)}},s},E=function(o,c,f=!0){let t=c(...o);const n=[];o.forEach(e=>{e.subscribe(()=>{u(f,()=>{t=c(...o),n.forEach(r=>r(t))})})});const s={on:()=>{throw new Error("Cannot call 'on' on combined store")},get(){return t},set(){throw new Error("Cannot call 'set' on combined store")},subscribe(e){return n.push(e),()=>{const r=n.indexOf(e);~r&&n.splice(r,1)}},enableOn(e){return e.subscribe(()=>f=!1),s},disableOn(e){return e.subscribe(()=>f=!0),s}};return s},p=function(o){const c=[],f={on:(t,n)=>(t==="onBefore"?n.onBefore(()=>c.forEach(s=>s()),o):t==="onSuccess"?n.onSuccess(()=>c.forEach(s=>s()),o):t==="onError"?n.onError(()=>c.forEach(s=>s()),o):n.onFinally(()=>c.forEach(s=>s()),o),f),subscribe:t=>{c.push(t)}};return f},a=function(o){return()=>o},k=function(o){const c=b(!1);return o.forEach(f=>{c.on(f,"onBefore",a(!0)),c.on(f,"onFinally",a(!1))}),c};exports.combine=E;exports.effect=A;exports.enableCheck=u;exports.marker=p;exports.pending=k;exports.store=b;exports.to=a;
|
package/dist/index.js
CHANGED
|
@@ -1,167 +1,175 @@
|
|
|
1
|
-
const u = function(
|
|
2
|
-
|
|
3
|
-
},
|
|
4
|
-
const
|
|
5
|
-
on: (n,
|
|
6
|
-
(...
|
|
7
|
-
|
|
8
|
-
() =>
|
|
1
|
+
const u = function(o, c) {
|
|
2
|
+
o && c();
|
|
3
|
+
}, b = function(o, c = !0) {
|
|
4
|
+
const f = [], l = {
|
|
5
|
+
on: (n, s, r) => (s === "onBefore" ? n.onBefore(
|
|
6
|
+
(...e) => u(
|
|
7
|
+
c,
|
|
8
|
+
() => {
|
|
9
|
+
o = r(o, { args: e }), f.forEach((t) => t(o));
|
|
10
|
+
}
|
|
9
11
|
)
|
|
10
|
-
) :
|
|
11
|
-
(
|
|
12
|
-
|
|
13
|
-
() =>
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
) : s === "onSuccess" ? n.onSuccess(
|
|
13
|
+
(e, ...t) => u(
|
|
14
|
+
c,
|
|
15
|
+
() => {
|
|
16
|
+
o = r(o, {
|
|
17
|
+
result: e,
|
|
18
|
+
args: t
|
|
19
|
+
}), f.forEach((i) => i(o));
|
|
20
|
+
}
|
|
17
21
|
)
|
|
18
|
-
) :
|
|
19
|
-
(
|
|
20
|
-
|
|
21
|
-
() =>
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
) : s === "onError" ? n.onError(
|
|
23
|
+
(e, ...t) => u(
|
|
24
|
+
c,
|
|
25
|
+
() => {
|
|
26
|
+
o = r(o, {
|
|
27
|
+
error: e,
|
|
28
|
+
args: t
|
|
29
|
+
}), f.forEach((i) => i(o));
|
|
30
|
+
}
|
|
25
31
|
)
|
|
26
32
|
) : n.onFinally(
|
|
27
|
-
(...
|
|
28
|
-
|
|
29
|
-
() =>
|
|
33
|
+
(...e) => u(
|
|
34
|
+
c,
|
|
35
|
+
() => o = r(o, { args: e })
|
|
30
36
|
)
|
|
31
|
-
),
|
|
37
|
+
), l),
|
|
32
38
|
get() {
|
|
33
|
-
return
|
|
39
|
+
return o;
|
|
34
40
|
},
|
|
35
41
|
set(n) {
|
|
36
|
-
|
|
42
|
+
o = n;
|
|
37
43
|
},
|
|
38
44
|
subscribe(n) {
|
|
39
|
-
return () => {
|
|
45
|
+
return f.push(n), () => {
|
|
46
|
+
const s = f.indexOf(n);
|
|
47
|
+
~s && f.splice(s, 1);
|
|
40
48
|
};
|
|
41
49
|
},
|
|
42
50
|
enableOn(n) {
|
|
43
|
-
return n.subscribe(() =>
|
|
51
|
+
return n.subscribe(() => c = !0), l;
|
|
44
52
|
},
|
|
45
53
|
disableOn(n) {
|
|
46
|
-
return n.subscribe(() =>
|
|
54
|
+
return n.subscribe(() => c = !1), l;
|
|
47
55
|
}
|
|
48
56
|
};
|
|
49
|
-
return
|
|
57
|
+
return l;
|
|
50
58
|
}, h = function() {
|
|
51
59
|
return {
|
|
52
60
|
afterAll: [],
|
|
53
61
|
beforeAll: [],
|
|
54
62
|
other: []
|
|
55
63
|
};
|
|
56
|
-
},
|
|
57
|
-
const
|
|
58
|
-
return
|
|
59
|
-
throw
|
|
64
|
+
}, A = function(o) {
|
|
65
|
+
const c = h(), f = h(), l = h(), n = h(), s = async function(...r) {
|
|
66
|
+
return c.beforeAll.forEach((e) => e(...r)), c.other.forEach((e) => e(...r)), c.afterAll.forEach((e) => e(...r)), o(...r).then((e) => (f.beforeAll.forEach((t) => t(e, ...r)), f.other.forEach((t) => t(e, ...r)), f.afterAll.forEach((t) => t(e, ...r)), e)).catch((e) => {
|
|
67
|
+
throw l.beforeAll.forEach((t) => t(e, ...r)), l.other.forEach((t) => t(e, ...r)), l.afterAll.forEach((t) => t(e, ...r)), e;
|
|
60
68
|
}).finally(() => {
|
|
61
|
-
|
|
69
|
+
n.beforeAll.forEach((e) => e(...r)), n.other.forEach((e) => e(...r)), n.afterAll.forEach((e) => e(...r));
|
|
62
70
|
});
|
|
63
71
|
};
|
|
64
|
-
return
|
|
72
|
+
return s.onBefore = (r, e) => {
|
|
65
73
|
switch (e) {
|
|
66
74
|
case "beforeAll":
|
|
67
|
-
|
|
75
|
+
c.beforeAll.push(r);
|
|
68
76
|
break;
|
|
69
77
|
case "afterAll":
|
|
70
|
-
|
|
78
|
+
c.afterAll.push(r);
|
|
71
79
|
break;
|
|
72
80
|
default:
|
|
73
|
-
|
|
81
|
+
c.other.push(r);
|
|
74
82
|
}
|
|
75
|
-
},
|
|
83
|
+
}, s.onSuccess = (r, e) => {
|
|
76
84
|
switch (e) {
|
|
77
85
|
case "beforeAll":
|
|
78
|
-
|
|
86
|
+
f.beforeAll.push(r);
|
|
79
87
|
break;
|
|
80
88
|
case "afterAll":
|
|
81
|
-
|
|
89
|
+
f.afterAll.push(r);
|
|
82
90
|
break;
|
|
83
91
|
default:
|
|
84
|
-
|
|
92
|
+
f.other.push(r);
|
|
85
93
|
}
|
|
86
|
-
},
|
|
94
|
+
}, s.onError = (r, e) => {
|
|
87
95
|
switch (e) {
|
|
88
96
|
case "beforeAll":
|
|
89
|
-
|
|
97
|
+
l.beforeAll.push(r);
|
|
90
98
|
break;
|
|
91
99
|
case "afterAll":
|
|
92
|
-
|
|
100
|
+
l.afterAll.push(r);
|
|
93
101
|
break;
|
|
94
102
|
default:
|
|
95
|
-
|
|
103
|
+
l.other.push(r);
|
|
96
104
|
}
|
|
97
|
-
},
|
|
105
|
+
}, s.onFinally = (r, e) => {
|
|
98
106
|
switch (e) {
|
|
99
107
|
case "beforeAll":
|
|
100
|
-
|
|
108
|
+
n.beforeAll.push(r);
|
|
101
109
|
break;
|
|
102
110
|
case "afterAll":
|
|
103
|
-
|
|
111
|
+
n.afterAll.push(r);
|
|
104
112
|
break;
|
|
105
113
|
default:
|
|
106
|
-
|
|
114
|
+
n.other.push(r);
|
|
107
115
|
}
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
let
|
|
111
|
-
const
|
|
112
|
-
|
|
116
|
+
}, s;
|
|
117
|
+
}, E = function(o, c, f = !0) {
|
|
118
|
+
let l = c(...o);
|
|
119
|
+
const n = [];
|
|
120
|
+
o.forEach((r) => {
|
|
113
121
|
r.subscribe(() => {
|
|
114
|
-
u(
|
|
115
|
-
|
|
122
|
+
u(f, () => {
|
|
123
|
+
l = c(...o), n.forEach((e) => e(l));
|
|
116
124
|
});
|
|
117
125
|
});
|
|
118
126
|
});
|
|
119
|
-
const
|
|
127
|
+
const s = {
|
|
120
128
|
on: () => {
|
|
121
129
|
throw new Error("Cannot call 'on' on combined store");
|
|
122
130
|
},
|
|
123
131
|
get() {
|
|
124
|
-
return
|
|
132
|
+
return l;
|
|
125
133
|
},
|
|
126
134
|
set() {
|
|
127
135
|
throw new Error("Cannot call 'set' on combined store");
|
|
128
136
|
},
|
|
129
137
|
subscribe(r) {
|
|
130
|
-
return
|
|
131
|
-
const e =
|
|
132
|
-
~e &&
|
|
138
|
+
return n.push(r), () => {
|
|
139
|
+
const e = n.indexOf(r);
|
|
140
|
+
~e && n.splice(e, 1);
|
|
133
141
|
};
|
|
134
142
|
},
|
|
135
143
|
enableOn(r) {
|
|
136
|
-
return r.subscribe(() =>
|
|
144
|
+
return r.subscribe(() => f = !1), s;
|
|
137
145
|
},
|
|
138
146
|
disableOn(r) {
|
|
139
|
-
return r.subscribe(() =>
|
|
147
|
+
return r.subscribe(() => f = !0), s;
|
|
140
148
|
}
|
|
141
149
|
};
|
|
142
|
-
return
|
|
143
|
-
},
|
|
144
|
-
const
|
|
145
|
-
on: (
|
|
146
|
-
subscribe: (
|
|
147
|
-
|
|
150
|
+
return s;
|
|
151
|
+
}, p = function(o) {
|
|
152
|
+
const c = [], f = {
|
|
153
|
+
on: (l, n) => (l === "onBefore" ? n.onBefore(() => c.forEach((s) => s()), o) : l === "onSuccess" ? n.onSuccess(() => c.forEach((s) => s()), o) : l === "onError" ? n.onError(() => c.forEach((s) => s()), o) : n.onFinally(() => c.forEach((s) => s()), o), f),
|
|
154
|
+
subscribe: (l) => {
|
|
155
|
+
c.push(l);
|
|
148
156
|
}
|
|
149
157
|
};
|
|
150
|
-
return
|
|
151
|
-
},
|
|
152
|
-
return () =>
|
|
153
|
-
},
|
|
154
|
-
const
|
|
155
|
-
return
|
|
156
|
-
|
|
157
|
-
}),
|
|
158
|
+
return f;
|
|
159
|
+
}, a = function(o) {
|
|
160
|
+
return () => o;
|
|
161
|
+
}, w = function(o) {
|
|
162
|
+
const c = b(!1);
|
|
163
|
+
return o.forEach((f) => {
|
|
164
|
+
c.on(f, "onBefore", a(!0)), c.on(f, "onFinally", a(!1));
|
|
165
|
+
}), c;
|
|
158
166
|
};
|
|
159
167
|
export {
|
|
160
|
-
|
|
161
|
-
|
|
168
|
+
E as combine,
|
|
169
|
+
A as effect,
|
|
162
170
|
u as enableCheck,
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
171
|
+
p as marker,
|
|
172
|
+
w as pending,
|
|
173
|
+
b as store,
|
|
174
|
+
a as to
|
|
167
175
|
};
|
package/package.json
CHANGED
package/src/store/index.ts
CHANGED
|
@@ -64,25 +64,34 @@ export const store = function <State extends any> (state: State, enabled: boolea
|
|
|
64
64
|
effect.onBefore((...args) =>
|
|
65
65
|
enableCheck(
|
|
66
66
|
enabled,
|
|
67
|
-
() =>
|
|
67
|
+
() => {
|
|
68
|
+
state = (handler as StoreOnBeforeHandler<State, Action>)(state, { args });
|
|
69
|
+
listeners.forEach((listener) => listener(state));
|
|
70
|
+
},
|
|
68
71
|
),
|
|
69
72
|
);
|
|
70
73
|
} else if (event === 'onSuccess') {
|
|
71
74
|
effect.onSuccess((result, ...args) =>
|
|
72
75
|
enableCheck(
|
|
73
76
|
enabled,
|
|
74
|
-
() =>
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
() => {
|
|
78
|
+
state = (handler as StoreOnSuccessHandler<State, Action>)(state, {
|
|
79
|
+
result, args,
|
|
80
|
+
});
|
|
81
|
+
listeners.forEach((listener) => listener(state));
|
|
82
|
+
},
|
|
77
83
|
),
|
|
78
84
|
);
|
|
79
85
|
} else if (event === 'onError') {
|
|
80
86
|
effect.onError((error, ...args) =>
|
|
81
87
|
enableCheck(
|
|
82
88
|
enabled,
|
|
83
|
-
() =>
|
|
84
|
-
|
|
85
|
-
|
|
89
|
+
() => {
|
|
90
|
+
state = (handler as StoreOnErrorHandler<State, Action>)(state, {
|
|
91
|
+
error, args,
|
|
92
|
+
});
|
|
93
|
+
listeners.forEach((listener) => listener(state));
|
|
94
|
+
},
|
|
86
95
|
),
|
|
87
96
|
);
|
|
88
97
|
} else {
|