ezh 0.1.6 → 0.2.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/lib/RbTree.js +19 -19
- package/lib/bundle.min.js +1 -1
- package/lib/debugCheck.js +37 -37
- package/lib/elements.js +450 -450
- package/lib/index.d.ts +1 -1
- package/lib/router.js +20 -20
- package/lib/state.js +188 -202
- package/package.json +2 -3
package/lib/index.d.ts
CHANGED
|
@@ -517,7 +517,7 @@ export declare const bindData: <T extends State<T>, K extends keyof T>(data: T,
|
|
|
517
517
|
K,
|
|
518
518
|
T[K]
|
|
519
519
|
];
|
|
520
|
-
export declare const useState: <T extends State<T>>(initial: T
|
|
520
|
+
export declare const useState: <T extends State<T>>(initial: T, hook?: (ver: number, state: T) => void) => T;
|
|
521
521
|
export declare const navigate: (to: string, replace?: true) => void;
|
|
522
522
|
export declare const route: <ParamT extends object>(com: Com<ParamT>, path: string, needAuth?: boolean) => IRoute<ParamT>;
|
|
523
523
|
export declare const Router: Com<RouterProp>;
|
package/lib/router.js
CHANGED
|
@@ -2,10 +2,10 @@ import { Path } from 'path-parser';
|
|
|
2
2
|
import { $ezh } from './elements';
|
|
3
3
|
import { useState } from './state';
|
|
4
4
|
export { navigate, route, Router, Link, RouteLink, };
|
|
5
|
-
let
|
|
6
|
-
const
|
|
5
|
+
let c = 0;
|
|
6
|
+
const d = useState({ ver: 0 });
|
|
7
7
|
window.addEventListener('popstate', () => {
|
|
8
|
-
|
|
8
|
+
d.ver = ++c;
|
|
9
9
|
});
|
|
10
10
|
const navigate = (to, replace) => {
|
|
11
11
|
const { pathname, search, hash } = window.location;
|
|
@@ -18,15 +18,15 @@ const navigate = (to, replace) => {
|
|
|
18
18
|
window.history.replaceState(undefined, '', to);
|
|
19
19
|
}
|
|
20
20
|
queueMicrotask(() => {
|
|
21
|
-
|
|
21
|
+
d.ver = ++c;
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
|
-
const
|
|
26
|
-
class
|
|
25
|
+
const e = 'ezhEZH';
|
|
26
|
+
class h {
|
|
27
27
|
constructor(com, path, needAuth) {
|
|
28
28
|
this.com = com;
|
|
29
|
-
this.b = Path.createPath(path +
|
|
29
|
+
this.b = Path.createPath(path + e);
|
|
30
30
|
this.needAuth = needAuth;
|
|
31
31
|
}
|
|
32
32
|
com;
|
|
@@ -34,16 +34,16 @@ class i {
|
|
|
34
34
|
parseParam(url) {
|
|
35
35
|
const param = this.b.test(url);
|
|
36
36
|
if (param) {
|
|
37
|
-
delete param[
|
|
37
|
+
delete param[e];
|
|
38
38
|
return param;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
buildUrl(
|
|
41
|
+
buildUrl(j) {
|
|
42
42
|
throw new Error('WildcardRoute does not support buildUrl');
|
|
43
43
|
}
|
|
44
44
|
b;
|
|
45
45
|
}
|
|
46
|
-
class
|
|
46
|
+
class i {
|
|
47
47
|
constructor(com, path, needAuth) {
|
|
48
48
|
this.com = com;
|
|
49
49
|
this.b = Path.createPath(path);
|
|
@@ -60,10 +60,10 @@ class j {
|
|
|
60
60
|
b;
|
|
61
61
|
}
|
|
62
62
|
const route = (com, path, needAuth = true) => {
|
|
63
|
-
return path.endsWith('*') ? new
|
|
63
|
+
return path.endsWith('*') ? new h(com, path, needAuth) : new i(com, path, needAuth);
|
|
64
64
|
};
|
|
65
65
|
const Router = ({ routes, notFound, checkAuth }) => {
|
|
66
|
-
|
|
66
|
+
c = d.ver;
|
|
67
67
|
const { pathname, search, hash } = window.location;
|
|
68
68
|
const a = `${pathname}${search}${hash}`;
|
|
69
69
|
const { $s, $k, $c } = $ezh;
|
|
@@ -72,9 +72,9 @@ const Router = ({ routes, notFound, checkAuth }) => {
|
|
|
72
72
|
const param = route.parseParam(a);
|
|
73
73
|
if (param) {
|
|
74
74
|
if (checkAuth && route.needAuth) {
|
|
75
|
-
const
|
|
76
|
-
if (
|
|
77
|
-
navigate(
|
|
75
|
+
const f = checkAuth(a);
|
|
76
|
+
if (f) {
|
|
77
|
+
navigate(f);
|
|
78
78
|
return;
|
|
79
79
|
}
|
|
80
80
|
}
|
|
@@ -83,8 +83,8 @@ const Router = ({ routes, notFound, checkAuth }) => {
|
|
|
83
83
|
}
|
|
84
84
|
return notFound ? $s($k('404'), $c('_', notFound, {})) : undefined;
|
|
85
85
|
};
|
|
86
|
-
const
|
|
87
|
-
|
|
86
|
+
const g = (u, url, replace) => {
|
|
87
|
+
u.preventDefault();
|
|
88
88
|
const { pathname, search, hash } = window.location;
|
|
89
89
|
const a = `${pathname}${search}${hash}`;
|
|
90
90
|
if (url !== a) {
|
|
@@ -94,18 +94,18 @@ const h = (v, url, replace) => {
|
|
|
94
94
|
else {
|
|
95
95
|
window.history.replaceState(undefined, '', url);
|
|
96
96
|
}
|
|
97
|
-
|
|
97
|
+
d.ver = ++c;
|
|
98
98
|
}
|
|
99
99
|
};
|
|
100
100
|
const Link = (props, children) => {
|
|
101
101
|
const { href, className, style, title, replace } = props;
|
|
102
|
-
const onclick = href ? (
|
|
102
|
+
const onclick = href ? (u) => g(u, href, replace) : undefined;
|
|
103
103
|
return $ezh.$('_', 'a', { className, style, title, href, onclick }, children, -1, 1);
|
|
104
104
|
};
|
|
105
105
|
const RouteLink = (props, children) => {
|
|
106
106
|
const { route, params, className, style, title, replace } = props;
|
|
107
107
|
const href = route.buildUrl(params);
|
|
108
|
-
const onclick = (
|
|
108
|
+
const onclick = (u) => g(u, href, replace);
|
|
109
109
|
return $ezh.$('_', 'a', { className, style, title, href, onclick }, children, -1, 1);
|
|
110
110
|
};
|
|
111
111
|
//# sourceMappingURL=router.js.map
|
package/lib/state.js
CHANGED
|
@@ -1,86 +1,86 @@
|
|
|
1
|
-
import { addComReader,
|
|
2
|
-
const
|
|
3
|
-
const
|
|
1
|
+
import { addComReader, o, refreshComReaders } from './elements';
|
|
2
|
+
const i = Symbol();
|
|
3
|
+
const k = Array.prototype;
|
|
4
4
|
const x = addComReader;
|
|
5
|
-
let
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
let m = (readerRecord, key) => {
|
|
6
|
+
m = refreshComReaders;
|
|
7
|
+
m(readerRecord, key);
|
|
8
8
|
};
|
|
9
|
-
export let
|
|
9
|
+
export let u = false;
|
|
10
10
|
export const y = new WeakMap();
|
|
11
|
-
const
|
|
12
|
-
return function (...
|
|
13
|
-
const
|
|
14
|
-
let begin,
|
|
11
|
+
const r = (_) => {
|
|
12
|
+
return function (...n) {
|
|
13
|
+
const h = this.length;
|
|
14
|
+
let begin, d, l;
|
|
15
15
|
switch (_) {
|
|
16
|
-
case
|
|
17
|
-
begin =
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
case k.push:
|
|
17
|
+
begin = h;
|
|
18
|
+
d = begin + n.length;
|
|
19
|
+
l = h;
|
|
20
20
|
break;
|
|
21
|
-
case
|
|
21
|
+
case k.unshift:
|
|
22
22
|
begin = 0;
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
d = n.length;
|
|
24
|
+
l = h;
|
|
25
25
|
break;
|
|
26
|
-
case
|
|
27
|
-
begin =
|
|
28
|
-
if (begin === undefined || begin <= -
|
|
26
|
+
case k.fill:
|
|
27
|
+
begin = n[1];
|
|
28
|
+
if (begin === undefined || begin <= -h) {
|
|
29
29
|
begin = 0;
|
|
30
30
|
}
|
|
31
31
|
else if (begin < 0) {
|
|
32
|
-
begin =
|
|
32
|
+
begin = h + begin;
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
if (
|
|
36
|
-
|
|
34
|
+
d = n[2];
|
|
35
|
+
if (d === undefined || d > h) {
|
|
36
|
+
d = h;
|
|
37
37
|
}
|
|
38
|
-
else if (
|
|
39
|
-
|
|
38
|
+
else if (d <= -h) {
|
|
39
|
+
d = 0;
|
|
40
40
|
}
|
|
41
|
-
else if (
|
|
42
|
-
|
|
41
|
+
else if (d < 0) {
|
|
42
|
+
d = h + d;
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
l = d;
|
|
45
45
|
break;
|
|
46
|
-
case
|
|
47
|
-
case
|
|
48
|
-
begin =
|
|
49
|
-
|
|
46
|
+
case k.sort:
|
|
47
|
+
case k.reverse:
|
|
48
|
+
begin = d = 0;
|
|
49
|
+
l = h;
|
|
50
50
|
break;
|
|
51
|
-
case
|
|
52
|
-
begin =
|
|
53
|
-
|
|
51
|
+
case k.pop:
|
|
52
|
+
begin = d = h - 1;
|
|
53
|
+
l = h;
|
|
54
54
|
break;
|
|
55
|
-
case
|
|
56
|
-
begin =
|
|
57
|
-
|
|
55
|
+
case k.shift:
|
|
56
|
+
begin = d = 0;
|
|
57
|
+
l = h;
|
|
58
58
|
break;
|
|
59
59
|
default:
|
|
60
|
-
begin =
|
|
60
|
+
begin = n[0];
|
|
61
61
|
if (begin < 0) {
|
|
62
|
-
begin =
|
|
62
|
+
begin = h + begin;
|
|
63
63
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (
|
|
67
|
-
|
|
64
|
+
d = n.length > 2 ? n.length - 2 : 0;
|
|
65
|
+
l = n[1];
|
|
66
|
+
if (l === undefined) {
|
|
67
|
+
l = h - begin;
|
|
68
68
|
}
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
l = l > 0 ? (l !== d ? h : begin + d) : (d ? h : begin);
|
|
70
|
+
d += begin;
|
|
71
71
|
}
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
let
|
|
75
|
-
for (let b = begin; b <
|
|
76
|
-
|
|
77
|
-
switch (typeof
|
|
72
|
+
const e = _.bind(this)(...n);
|
|
73
|
+
const p = this[i];
|
|
74
|
+
let q;
|
|
75
|
+
for (let b = begin; b < d; b++) {
|
|
76
|
+
q = this[b];
|
|
77
|
+
switch (typeof q) {
|
|
78
78
|
case 'object':
|
|
79
|
-
if (
|
|
80
|
-
while (b <
|
|
81
|
-
|
|
82
|
-
if (
|
|
83
|
-
this[b] =
|
|
79
|
+
if (q) {
|
|
80
|
+
while (b < d) {
|
|
81
|
+
q = this[b];
|
|
82
|
+
if (q && !q[i]) {
|
|
83
|
+
this[b] = s(q);
|
|
84
84
|
}
|
|
85
85
|
b++;
|
|
86
86
|
}
|
|
@@ -91,126 +91,126 @@ const q = (_) => {
|
|
|
91
91
|
}
|
|
92
92
|
break;
|
|
93
93
|
}
|
|
94
|
-
if (
|
|
95
|
-
|
|
94
|
+
if (h !== this.length) {
|
|
95
|
+
m(p, 'length');
|
|
96
96
|
}
|
|
97
|
-
|
|
98
|
-
return
|
|
97
|
+
m(p, Symbol.iterator);
|
|
98
|
+
return e;
|
|
99
99
|
};
|
|
100
100
|
};
|
|
101
|
-
const
|
|
102
|
-
'push':
|
|
103
|
-
'unshift':
|
|
104
|
-
'fill':
|
|
105
|
-
'sort':
|
|
106
|
-
'reverse':
|
|
107
|
-
'pop':
|
|
108
|
-
'shift':
|
|
109
|
-
'splice':
|
|
101
|
+
const C = {
|
|
102
|
+
'push': r(k.push),
|
|
103
|
+
'unshift': r(k.unshift),
|
|
104
|
+
'fill': r(k.fill),
|
|
105
|
+
'sort': r(k.sort),
|
|
106
|
+
'reverse': r(k.reverse),
|
|
107
|
+
'pop': r(k.pop),
|
|
108
|
+
'shift': r(k.shift),
|
|
109
|
+
'splice': r(k.splice),
|
|
110
110
|
};
|
|
111
|
-
const
|
|
112
|
-
const
|
|
113
|
-
const
|
|
111
|
+
const D = (target, f) => {
|
|
112
|
+
const w = f.length;
|
|
113
|
+
const h = target.length;
|
|
114
114
|
let g;
|
|
115
|
-
for (let b = 0; b <
|
|
116
|
-
let
|
|
117
|
-
if (
|
|
115
|
+
for (let b = 0; b < w; b++) {
|
|
116
|
+
let c = f[b];
|
|
117
|
+
if (c && typeof c === 'object') {
|
|
118
118
|
do {
|
|
119
|
-
|
|
119
|
+
c = f[b];
|
|
120
120
|
g = target[b];
|
|
121
|
-
if (
|
|
121
|
+
if (c) {
|
|
122
122
|
if (g) {
|
|
123
|
-
if (g !==
|
|
124
|
-
g[
|
|
123
|
+
if (g !== c) {
|
|
124
|
+
g[i] = c;
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
else {
|
|
128
|
-
target[b] =
|
|
128
|
+
target[b] = s(c);
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
else {
|
|
132
|
-
target[b] =
|
|
132
|
+
target[b] = c;
|
|
133
133
|
}
|
|
134
|
-
} while (++b <
|
|
134
|
+
} while (++b < w);
|
|
135
135
|
break;
|
|
136
136
|
}
|
|
137
|
-
else if (
|
|
137
|
+
else if (c !== null && c !== undefined) {
|
|
138
138
|
do {
|
|
139
|
-
target[b] =
|
|
140
|
-
} while (++b <
|
|
139
|
+
target[b] = f[b];
|
|
140
|
+
} while (++b < w);
|
|
141
141
|
break;
|
|
142
142
|
}
|
|
143
143
|
else {
|
|
144
|
-
target[b] =
|
|
144
|
+
target[b] = c;
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
|
-
const
|
|
148
|
-
if (
|
|
149
|
-
if (
|
|
150
|
-
target.length =
|
|
147
|
+
const p = target[i];
|
|
148
|
+
if (h !== w) {
|
|
149
|
+
if (h > w) {
|
|
150
|
+
target.length = w;
|
|
151
151
|
}
|
|
152
|
-
|
|
152
|
+
m(p, 'length');
|
|
153
153
|
}
|
|
154
|
-
|
|
154
|
+
m(p, Symbol.iterator);
|
|
155
155
|
};
|
|
156
|
-
const
|
|
156
|
+
const E = (target, z, f) => {
|
|
157
157
|
const A = { ...target };
|
|
158
158
|
let g;
|
|
159
|
-
for (const
|
|
160
|
-
delete A[
|
|
161
|
-
const
|
|
162
|
-
if (
|
|
163
|
-
g = target[
|
|
159
|
+
for (const v in f) {
|
|
160
|
+
delete A[v];
|
|
161
|
+
const c = f[v];
|
|
162
|
+
if (c && typeof c === 'object') {
|
|
163
|
+
g = target[v];
|
|
164
164
|
if (g) {
|
|
165
|
-
g[
|
|
165
|
+
g[i] = c;
|
|
166
166
|
continue;
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
|
-
if (target[
|
|
170
|
-
z[
|
|
169
|
+
if (target[v] !== c) {
|
|
170
|
+
z[v] = c;
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
|
-
for (const
|
|
174
|
-
delete z[
|
|
173
|
+
for (const v in A) {
|
|
174
|
+
delete z[v];
|
|
175
175
|
}
|
|
176
176
|
};
|
|
177
|
-
const
|
|
177
|
+
const F = {
|
|
178
178
|
get(target, key) {
|
|
179
|
-
if (key !==
|
|
180
|
-
let
|
|
181
|
-
if (
|
|
182
|
-
const
|
|
183
|
-
if (
|
|
184
|
-
return
|
|
179
|
+
if (key !== i) {
|
|
180
|
+
let e = target[key];
|
|
181
|
+
if (e && e === k[key]) {
|
|
182
|
+
const B = C[key];
|
|
183
|
+
if (B) {
|
|
184
|
+
return B.bind(target);
|
|
185
185
|
}
|
|
186
|
-
|
|
186
|
+
e = e.bind(target);
|
|
187
187
|
}
|
|
188
|
-
x(target[
|
|
189
|
-
return
|
|
188
|
+
x(target[i], key !== 'length' ? Symbol.iterator : key);
|
|
189
|
+
return e;
|
|
190
190
|
}
|
|
191
191
|
return target;
|
|
192
192
|
},
|
|
193
|
-
set(target, key,
|
|
194
|
-
if (key !==
|
|
195
|
-
if (target[key] ===
|
|
193
|
+
set(target, key, f) {
|
|
194
|
+
if (key !== i) {
|
|
195
|
+
if (target[key] === f) {
|
|
196
196
|
return true;
|
|
197
197
|
}
|
|
198
|
-
const
|
|
199
|
-
if (
|
|
200
|
-
|
|
198
|
+
const p = target[i];
|
|
199
|
+
if (f && typeof f === 'object') {
|
|
200
|
+
f = s(f);
|
|
201
201
|
}
|
|
202
|
-
target[key] =
|
|
202
|
+
target[key] = f;
|
|
203
203
|
if (key === 'length') {
|
|
204
|
-
|
|
204
|
+
m(p, key);
|
|
205
205
|
}
|
|
206
|
-
|
|
206
|
+
m(p, Symbol.iterator);
|
|
207
207
|
return true;
|
|
208
208
|
}
|
|
209
|
-
|
|
209
|
+
D(target, f);
|
|
210
210
|
return true;
|
|
211
211
|
},
|
|
212
212
|
has(target, key) {
|
|
213
|
-
x(target[
|
|
213
|
+
x(target[i], !isNaN(parseInt(key)) ? Symbol.iterator : key);
|
|
214
214
|
return key in target;
|
|
215
215
|
},
|
|
216
216
|
deleteProperty(target, key) {
|
|
@@ -218,137 +218,123 @@ const G = {
|
|
|
218
218
|
key = Symbol.iterator;
|
|
219
219
|
}
|
|
220
220
|
if (target[key] !== undefined) {
|
|
221
|
-
|
|
221
|
+
m(target[i], key);
|
|
222
222
|
}
|
|
223
223
|
return delete target[key];
|
|
224
224
|
},
|
|
225
225
|
};
|
|
226
|
-
const
|
|
226
|
+
const G = {
|
|
227
227
|
get(target, key) {
|
|
228
|
-
if (key !==
|
|
229
|
-
const
|
|
228
|
+
if (key !== i) {
|
|
229
|
+
const e = target[key];
|
|
230
230
|
if (key !== 'id') {
|
|
231
|
-
x(target[
|
|
231
|
+
x(target[i], key);
|
|
232
232
|
}
|
|
233
|
-
return
|
|
233
|
+
return e;
|
|
234
234
|
}
|
|
235
235
|
return target;
|
|
236
236
|
},
|
|
237
|
-
set(target, key,
|
|
238
|
-
if (key !==
|
|
239
|
-
if (target[key] ===
|
|
237
|
+
set(target, key, f, z) {
|
|
238
|
+
if (key !== i) {
|
|
239
|
+
if (target[key] === f) {
|
|
240
240
|
return true;
|
|
241
241
|
}
|
|
242
|
-
const
|
|
243
|
-
if (
|
|
244
|
-
|
|
242
|
+
const p = target[i];
|
|
243
|
+
if (f && typeof f === 'object') {
|
|
244
|
+
f = s(f);
|
|
245
245
|
}
|
|
246
|
-
target[key] =
|
|
247
|
-
|
|
246
|
+
target[key] = f;
|
|
247
|
+
m(p, key);
|
|
248
248
|
return true;
|
|
249
249
|
}
|
|
250
|
-
|
|
250
|
+
E(target, z, f);
|
|
251
251
|
return true;
|
|
252
252
|
},
|
|
253
253
|
has(target, key) {
|
|
254
|
-
x(target[
|
|
254
|
+
x(target[i], key);
|
|
255
255
|
return key in target;
|
|
256
256
|
},
|
|
257
257
|
deleteProperty(target, key) {
|
|
258
258
|
if (target[key] !== undefined) {
|
|
259
|
-
|
|
259
|
+
m(target[i], key);
|
|
260
260
|
}
|
|
261
261
|
return delete target[key];
|
|
262
262
|
},
|
|
263
263
|
};
|
|
264
|
-
const
|
|
264
|
+
const s = (state) => {
|
|
265
265
|
let target;
|
|
266
|
-
if (!Array.isArray(
|
|
266
|
+
if (!Array.isArray(state)) {
|
|
267
267
|
target = {};
|
|
268
|
-
for (const key in
|
|
269
|
-
const
|
|
270
|
-
target[key] =
|
|
268
|
+
for (const key in state) {
|
|
269
|
+
const c = state[key];
|
|
270
|
+
target[key] = c && typeof c === 'object' ? s(c) : c;
|
|
271
271
|
}
|
|
272
|
-
|
|
272
|
+
state = new Proxy(target, G);
|
|
273
273
|
}
|
|
274
274
|
else {
|
|
275
275
|
target = [];
|
|
276
|
-
const length =
|
|
276
|
+
const length = state.length;
|
|
277
277
|
for (let b = 0; b < length; b++) {
|
|
278
|
-
let
|
|
279
|
-
if (
|
|
278
|
+
let c = state[b];
|
|
279
|
+
if (c && typeof c === 'object') {
|
|
280
280
|
do {
|
|
281
|
-
target[b] = (
|
|
281
|
+
target[b] = (c = state[b]) && s(c);
|
|
282
282
|
} while (++b < length);
|
|
283
283
|
break;
|
|
284
284
|
}
|
|
285
|
-
else if (
|
|
285
|
+
else if (c !== null && c !== undefined) {
|
|
286
286
|
do {
|
|
287
|
-
target[b] =
|
|
287
|
+
target[b] = state[b];
|
|
288
288
|
} while (++b < length);
|
|
289
289
|
break;
|
|
290
290
|
}
|
|
291
|
-
target[b] =
|
|
291
|
+
target[b] = c;
|
|
292
292
|
}
|
|
293
|
-
|
|
293
|
+
state = new Proxy(target, F);
|
|
294
294
|
}
|
|
295
|
-
target[
|
|
296
|
-
return
|
|
295
|
+
target[i] = {};
|
|
296
|
+
return state;
|
|
297
297
|
};
|
|
298
|
-
const $ = (
|
|
299
|
-
if (
|
|
300
|
-
|
|
298
|
+
const $ = (a, a1) => {
|
|
299
|
+
if (a1) {
|
|
300
|
+
a.ver = 0;
|
|
301
|
+
a.hook(0, a.state);
|
|
301
302
|
}
|
|
302
303
|
else {
|
|
303
|
-
|
|
304
|
+
a.com.watchMountChange('s', $, a);
|
|
304
305
|
}
|
|
305
306
|
};
|
|
306
307
|
export const bindData = (data, key) => {
|
|
307
308
|
return [data, key, data[key]];
|
|
308
309
|
};
|
|
309
|
-
export const useState = (initial,
|
|
310
|
-
const com =
|
|
310
|
+
export const useState = (initial, hook) => {
|
|
311
|
+
const com = o;
|
|
311
312
|
if (com.id) {
|
|
312
|
-
let
|
|
313
|
-
if (
|
|
314
|
-
const
|
|
315
|
-
if (
|
|
316
|
-
if (
|
|
317
|
-
|
|
318
|
-
initial = initial(e);
|
|
319
|
-
if (initial !== e) {
|
|
320
|
-
e[f] = initial;
|
|
321
|
-
}
|
|
322
|
-
t = false;
|
|
313
|
+
let t = y.get(com);
|
|
314
|
+
if (t) {
|
|
315
|
+
const { state, hook } = t;
|
|
316
|
+
if (hook) {
|
|
317
|
+
if (!t.ver) {
|
|
318
|
+
com.watchMountChange('s', $, t);
|
|
323
319
|
}
|
|
320
|
+
u = true;
|
|
321
|
+
hook(++t.ver, state);
|
|
322
|
+
u = false;
|
|
324
323
|
}
|
|
325
|
-
|
|
326
|
-
t = true;
|
|
327
|
-
if (typeof initial === 'function') {
|
|
328
|
-
initial = initial();
|
|
329
|
-
}
|
|
330
|
-
e[f] = initial;
|
|
331
|
-
t = false;
|
|
332
|
-
s.w = false;
|
|
333
|
-
com.watchMountChange('s', $, s);
|
|
334
|
-
}
|
|
335
|
-
return e;
|
|
324
|
+
return state;
|
|
336
325
|
}
|
|
337
|
-
|
|
338
|
-
|
|
326
|
+
const state = s(initial);
|
|
327
|
+
t = { com, state, ver: 1, hook };
|
|
328
|
+
y.set(com, t);
|
|
329
|
+
if (hook) {
|
|
330
|
+
com.watchMountChange('s', $, t);
|
|
331
|
+
u = true;
|
|
332
|
+
hook(1, state);
|
|
333
|
+
u = false;
|
|
339
334
|
}
|
|
340
|
-
|
|
341
|
-
s = { com, e, w: false };
|
|
342
|
-
y.set(com, s);
|
|
343
|
-
if (resetOnUnmount) {
|
|
344
|
-
com.watchMountChange('s', $, s);
|
|
345
|
-
}
|
|
346
|
-
return e;
|
|
347
|
-
}
|
|
348
|
-
if (typeof initial === 'function') {
|
|
349
|
-
initial = initial();
|
|
335
|
+
return state;
|
|
350
336
|
}
|
|
351
|
-
const
|
|
352
|
-
return
|
|
337
|
+
const state = s(initial);
|
|
338
|
+
return state;
|
|
353
339
|
};
|
|
354
340
|
//# sourceMappingURL=state.js.map
|