lithent 1.0.1 → 1.0.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/README.md +20 -17
- package/dist/lithent.mjs +126 -133
- package/dist/lithent.mjs.map +1 -1
- package/dist/lithent.umd.js +1 -1
- package/dist/lithent.umd.js.map +1 -1
- package/dist/types/index.d.ts +6 -6
- package/dist/utils/index.d.ts +16 -0
- package/dist/utils/universalRef.d.ts +6 -6
- package/dist/wDom.d.ts +2 -2
- package/examples/dist/assets/index.1e9792b7.js +2 -0
- package/examples/dist/assets/index.1e9792b7.js.map +1 -0
- package/examples/dist/index.html +1 -1
- package/package.json +1 -1
- package/src/diff.ts +16 -13
- package/src/hook/mountCallback.ts +6 -6
- package/src/hook/unmount.ts +7 -7
- package/src/hook/useUpdate.ts +6 -6
- package/src/render.ts +51 -57
- package/src/types/index.ts +6 -6
- package/src/utils/index.ts +7 -5
- package/src/utils/predicator.ts +5 -2
- package/src/utils/universalRef.ts +23 -28
- package/src/wDom.ts +25 -30
- package/examples/dist/assets/index.c9e026ab.js +0 -2
- package/examples/dist/assets/index.c9e026ab.js.map +0 -1
- /package/src/tests/{example1.tsx → test1.tsx} +0 -0
- /package/src/tests/{example10.tsx → test10.tsx} +0 -0
- /package/src/tests/{example11.tsx → test11.tsx} +0 -0
- /package/src/tests/{example12.tsx → test12.tsx} +0 -0
- /package/src/tests/{example13.tsx → test13.tsx} +0 -0
- /package/src/tests/{example14.tsx → test14.tsx} +0 -0
- /package/src/tests/{example15.tsx → test15.tsx} +0 -0
- /package/src/tests/{example16.tsx → test16.tsx} +0 -0
- /package/src/tests/{example17.tsx → test17.tsx} +0 -0
- /package/src/tests/{example2.tsx → test2.tsx} +0 -0
- /package/src/tests/{example3.tsx → test3.tsx} +0 -0
- /package/src/tests/{example4.tsx → test4.tsx} +0 -0
- /package/src/tests/{example5.tsx → test5.tsx} +0 -0
- /package/src/tests/{example6.tsx → test6.tsx} +0 -0
- /package/src/tests/{example7.tsx → test7.tsx} +0 -0
- /package/src/tests/{example8.tsx → test8.tsx} +0 -0
- /package/src/tests/{example9.tsx → test9.tsx} +0 -0
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ used lightly in a variety of situations.
|
|
|
9
9
|
- https://superlucky84.github.io/lithent
|
|
10
10
|
- (This guide page is written in lithent.)
|
|
11
11
|
|
|
12
|
-
`(9.
|
|
12
|
+
`(9.58 KiB / gzip: 3.63 KiB)`
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
## 🚩 Table of Contents
|
|
@@ -24,20 +24,20 @@ used lightly in a variety of situations.
|
|
|
24
24
|
- [Examples](#examples)
|
|
25
25
|
- [With ESM](#with-esm)
|
|
26
26
|
- [With UMD](#with-umd)
|
|
27
|
-
- [Test](#test)
|
|
28
27
|
- [Develop Guide](#develop-guide)
|
|
28
|
+
- [Test](#test)
|
|
29
29
|
|
|
30
30
|
## Why use Lithent?
|
|
31
31
|
|
|
32
32
|
### Lithent have the bare minimum of necessary functionality, with no unnecessary features.
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
In a real-world development environment, you may want to use Virtual DOM lightly, with only the bare minimum of core functionality.
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
"Lithent" makes it easy to add, remove, and update virtual domes to specific parts of a pre-drawn SSR page.
|
|
37
37
|
|
|
38
|
-
Lithent has implemented the bare minimum functionality needed to create and update virtual DOM in general (we only need to know 'render', 'mounter', 'updater', 'renewer', 'mountCallback', and 'updateCallback').
|
|
38
|
+
"Lithent" has implemented the bare minimum functionality needed to create and update virtual DOM in general (we only need to know 'render', 'mounter', 'updater', 'renewer', 'mountCallback', and 'updateCallback').
|
|
39
39
|
|
|
40
|
-
We provide code in the form of 'helpers' that extend the basic functionality, but using the helpers is only optional and
|
|
40
|
+
We provide code in the form of 'helpers' that extend the basic functionality, but using the helpers is only optional and users can extend and develop custom helpers for their own projects.
|
|
41
41
|
|
|
42
42
|
### Approach with the developer-friendly concept of closures between "component mounter" and "renderer"
|
|
43
43
|
|
|
@@ -98,15 +98,17 @@ import { state } from 'lithent/helper';
|
|
|
98
98
|
import htm from 'htm';
|
|
99
99
|
const html = htm.bind(h);
|
|
100
100
|
|
|
101
|
-
const Component = mount((
|
|
102
|
-
const count = state(0,
|
|
101
|
+
const Component = mount((renew, _props) => {
|
|
102
|
+
const count = state(0, renew);
|
|
103
103
|
|
|
104
|
-
const change = () =>
|
|
104
|
+
const change = () => {
|
|
105
|
+
count.value += 1;
|
|
106
|
+
};
|
|
105
107
|
|
|
106
108
|
// Updater
|
|
107
109
|
return () => html`
|
|
108
110
|
<${Fragment}>
|
|
109
|
-
<li>count: ${count.
|
|
111
|
+
<li>count: ${count.value}</li>
|
|
110
112
|
<button onClick=${change}>increase</button>
|
|
111
113
|
<//>
|
|
112
114
|
`;
|
|
@@ -154,13 +156,6 @@ const destroy = render(html`<${Component} />`, document.getElementById('root'));
|
|
|
154
156
|
</script>
|
|
155
157
|
```
|
|
156
158
|
|
|
157
|
-
## Test
|
|
158
|
-
|
|
159
|
-
```bash
|
|
160
|
-
// pnpm install
|
|
161
|
-
pnpm test
|
|
162
|
-
```
|
|
163
|
-
|
|
164
159
|
## Develop Guide
|
|
165
160
|
|
|
166
161
|
It's open source, so you can develop and contribute together.
|
|
@@ -192,3 +187,11 @@ pnpm build
|
|
|
192
187
|
```bash
|
|
193
188
|
pnpm dev // or pnpm dev:core
|
|
194
189
|
```
|
|
190
|
+
|
|
191
|
+
## Test
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
// pnpm install
|
|
195
|
+
pnpm test
|
|
196
|
+
```
|
|
197
|
+
|
package/dist/lithent.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const checkPlainWDomType = (wDom) => typeof wDom === "object" && !("resolve" in wDom);
|
|
2
2
|
const checkPlainType = (wDom, typeName) => checkPlainWDomType(wDom) && wDom.type === typeName;
|
|
3
|
-
const checkSameCustomComponent = (newWDom, originalWDom) => newWDom.
|
|
3
|
+
const checkSameCustomComponent = (newWDom, originalWDom) => "ctor" in newWDom ? newWDom.ctor === (originalWDom == null ? void 0 : originalWDom.ctor) : newWDom === (originalWDom == null ? void 0 : originalWDom.ctor);
|
|
4
4
|
const checkSameFragment = (newWDom, originalWDom) => {
|
|
5
5
|
var _a, _b;
|
|
6
6
|
return checkPlainWDomType(newWDom) && (originalWDom == null ? void 0 : originalWDom.type) === "fragment" && ((_a = originalWDom == null ? void 0 : originalWDom.children) == null ? void 0 : _a.length) === ((_b = newWDom == null ? void 0 : newWDom.children) == null ? void 0 : _b.length);
|
|
@@ -15,7 +15,7 @@ const checkNormalTypeElement = (newWDom, originalWDom) => {
|
|
|
15
15
|
};
|
|
16
16
|
const getKey = (target) => {
|
|
17
17
|
var _a, _b, _c;
|
|
18
|
-
return (_c = (_a = target == null ? void 0 : target.
|
|
18
|
+
return (_c = (_a = target == null ? void 0 : target.compProps) == null ? void 0 : _a.key) != null ? _c : (_b = target == null ? void 0 : target.props) == null ? void 0 : _b.key;
|
|
19
19
|
};
|
|
20
20
|
const checkVirtualType = (type) => type && ["fragment", "loop"].includes(type);
|
|
21
21
|
const checkCustemComponentFunction = (target) => typeof target === "function" && !checkFragmentFunction(target) || typeof target === "object" && "resolve" in target;
|
|
@@ -58,7 +58,7 @@ const getParent = (vDom) => {
|
|
|
58
58
|
return parentVDom;
|
|
59
59
|
};
|
|
60
60
|
const reRender = (vDom, infoVdom) => {
|
|
61
|
-
const {
|
|
61
|
+
const { compProps: props, compChild: children } = vDom;
|
|
62
62
|
const { props: infoProps, children: infoChidren } = infoVdom;
|
|
63
63
|
if (props) {
|
|
64
64
|
updateProps$1(props, infoProps);
|
|
@@ -71,12 +71,13 @@ const reRender = (vDom, infoVdom) => {
|
|
|
71
71
|
};
|
|
72
72
|
const getEventName = (eventKey) => eventKey.replace(/^on(.*)/, (_match, p1) => p1.toLowerCase());
|
|
73
73
|
const getAttrKey = (keyName) => keyName === "className" ? "class" : keyName;
|
|
74
|
+
const entries = Object.entries;
|
|
75
|
+
const keys = Object.keys;
|
|
76
|
+
const assign = Object.assign;
|
|
74
77
|
const updateProps$1 = (props, infoProps) => {
|
|
75
78
|
if (props && infoProps !== props) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
([key, value]) => props[key] = value
|
|
79
|
-
);
|
|
79
|
+
keys(props).forEach((key) => delete props[key]);
|
|
80
|
+
entries(infoProps || {}).forEach(([key, value]) => props[key] = value);
|
|
80
81
|
}
|
|
81
82
|
};
|
|
82
83
|
const updateChildren = (children, infoChidren) => {
|
|
@@ -90,12 +91,12 @@ const updateChildren = (children, infoChidren) => {
|
|
|
90
91
|
let redrawQueue = [];
|
|
91
92
|
let redrawQueueTimeout = false;
|
|
92
93
|
const xmlnsRef = { value: "" };
|
|
93
|
-
const
|
|
94
|
+
const compKeyRef = { value: {} };
|
|
94
95
|
const needDiffRef = { value: false };
|
|
95
96
|
const componentRef = /* @__PURE__ */ new WeakMap();
|
|
96
|
-
const componentRender = (
|
|
97
|
+
const componentRender = (compKey) => () => {
|
|
97
98
|
var _a;
|
|
98
|
-
const up = (_a = componentRef.get(
|
|
99
|
+
const up = (_a = componentRef.get(compKey)) == null ? void 0 : _a.up;
|
|
99
100
|
let result = false;
|
|
100
101
|
if (up) {
|
|
101
102
|
up();
|
|
@@ -103,8 +104,8 @@ const componentRender = (componentKey) => () => {
|
|
|
103
104
|
}
|
|
104
105
|
return result;
|
|
105
106
|
};
|
|
106
|
-
const setComponetRef = (
|
|
107
|
-
componentRef.set(
|
|
107
|
+
const setComponetRef = (compKey) => {
|
|
108
|
+
componentRef.set(compKey, {
|
|
108
109
|
vd: { value: null },
|
|
109
110
|
up: () => {
|
|
110
111
|
},
|
|
@@ -116,12 +117,12 @@ const setComponetRef = (componentKey) => {
|
|
|
116
117
|
umts: []
|
|
117
118
|
});
|
|
118
119
|
};
|
|
119
|
-
const getComponentKey = () =>
|
|
120
|
-
const getComponentSubInfo = (
|
|
121
|
-
const setRedrawAction = (
|
|
122
|
-
componentRef.get(
|
|
120
|
+
const getComponentKey = () => compKeyRef.value;
|
|
121
|
+
const getComponentSubInfo = (compKey, subKey) => componentRef.get(compKey)[subKey];
|
|
122
|
+
const setRedrawAction = (compKey, exec) => {
|
|
123
|
+
componentRef.get(compKey).up = () => {
|
|
123
124
|
redrawQueue.push({
|
|
124
|
-
|
|
125
|
+
compKey,
|
|
125
126
|
exec
|
|
126
127
|
});
|
|
127
128
|
if (!redrawQueueTimeout) {
|
|
@@ -130,14 +131,14 @@ const setRedrawAction = (componentKey, exec) => {
|
|
|
130
131
|
}
|
|
131
132
|
};
|
|
132
133
|
};
|
|
133
|
-
const initUpdateHookState = (
|
|
134
|
-
const initMountHookState = (
|
|
135
|
-
|
|
136
|
-
setComponetRef(
|
|
134
|
+
const initUpdateHookState = (compKey) => compKeyRef.value = compKey;
|
|
135
|
+
const initMountHookState = (compKey) => {
|
|
136
|
+
compKeyRef.value = compKey;
|
|
137
|
+
setComponetRef(compKey);
|
|
137
138
|
};
|
|
138
139
|
const recursiveGetChildKeys = (wDom, result) => {
|
|
139
140
|
(wDom.children || []).forEach((item) => {
|
|
140
|
-
const childComKey = item.
|
|
141
|
+
const childComKey = item.compKey;
|
|
141
142
|
if (childComKey) {
|
|
142
143
|
result.push(childComKey);
|
|
143
144
|
}
|
|
@@ -148,18 +149,18 @@ const execRedrawQueue = () => {
|
|
|
148
149
|
let childItemList = [];
|
|
149
150
|
redrawQueue.forEach((item) => {
|
|
150
151
|
var _a, _b;
|
|
151
|
-
const childVd = (_b = (_a = componentRef.get(item.
|
|
152
|
+
const childVd = (_b = (_a = componentRef.get(item.compKey)) == null ? void 0 : _a.vd) == null ? void 0 : _b.value;
|
|
152
153
|
if (childVd) {
|
|
153
154
|
recursiveGetChildKeys(childVd, childItemList);
|
|
154
155
|
}
|
|
155
156
|
});
|
|
156
157
|
const addedKey = [];
|
|
157
158
|
const result = redrawQueue.reduce((acc, item) => {
|
|
158
|
-
const {
|
|
159
|
-
if (childItemList.includes(
|
|
159
|
+
const { compKey } = item;
|
|
160
|
+
if (childItemList.includes(compKey) || addedKey.includes(compKey)) {
|
|
160
161
|
return acc;
|
|
161
162
|
}
|
|
162
|
-
addedKey.push(
|
|
163
|
+
addedKey.push(compKey);
|
|
163
164
|
acc.push(item);
|
|
164
165
|
return acc;
|
|
165
166
|
}, []);
|
|
@@ -176,15 +177,15 @@ const unmount = (effectAction) => {
|
|
|
176
177
|
componentRef.get(getComponentKey()).umts.push(effectAction);
|
|
177
178
|
};
|
|
178
179
|
const runUnmountQueueFromWDom = (newWDom) => {
|
|
179
|
-
const {
|
|
180
|
-
if (
|
|
181
|
-
removeItem(
|
|
180
|
+
const { compKey } = newWDom;
|
|
181
|
+
if (compKey) {
|
|
182
|
+
removeItem(compKey);
|
|
182
183
|
}
|
|
183
184
|
recursiveRunUnmount(newWDom);
|
|
184
185
|
};
|
|
185
186
|
const recursiveRunUnmount = (wDom) => {
|
|
186
187
|
(wDom.children || []).forEach((item) => {
|
|
187
|
-
const childComKey = item.
|
|
188
|
+
const childComKey = item.compKey;
|
|
188
189
|
if (childComKey) {
|
|
189
190
|
runUnmountQueueFromWDom(item);
|
|
190
191
|
} else {
|
|
@@ -192,12 +193,12 @@ const recursiveRunUnmount = (wDom) => {
|
|
|
192
193
|
}
|
|
193
194
|
});
|
|
194
195
|
};
|
|
195
|
-
const removeItem = (
|
|
196
|
-
const subInfo = componentRef.get(
|
|
196
|
+
const removeItem = (compKey) => {
|
|
197
|
+
const subInfo = componentRef.get(compKey);
|
|
197
198
|
if (subInfo) {
|
|
198
199
|
subInfo.umts.forEach((effect) => effect());
|
|
199
200
|
subInfo.umts = [];
|
|
200
|
-
componentRef.delete(
|
|
201
|
+
componentRef.delete(compKey);
|
|
201
202
|
}
|
|
202
203
|
};
|
|
203
204
|
let mountedQueue = [];
|
|
@@ -206,18 +207,18 @@ const execMountedQueue = () => {
|
|
|
206
207
|
mountedQueue = [];
|
|
207
208
|
};
|
|
208
209
|
const addMountedQueue = (wDom) => {
|
|
209
|
-
if (wDom.
|
|
210
|
+
if (wDom.compKey) {
|
|
210
211
|
mountedQueue.push(wDom);
|
|
211
212
|
}
|
|
212
213
|
};
|
|
213
214
|
const mountCallback = (effectAction) => componentRef.get(getComponentKey()).mts.push(effectAction);
|
|
214
215
|
const runMountedQueueFromWDom = (newWDom) => {
|
|
215
|
-
const {
|
|
216
|
-
if (
|
|
217
|
-
const component = componentRef.get(
|
|
216
|
+
const { compKey } = newWDom;
|
|
217
|
+
if (compKey) {
|
|
218
|
+
const component = componentRef.get(compKey);
|
|
218
219
|
const queue = component == null ? void 0 : component.mts;
|
|
219
220
|
const sequence = component == null ? void 0 : component.upS;
|
|
220
|
-
|
|
221
|
+
compKeyRef.value = compKey;
|
|
221
222
|
if (sequence) {
|
|
222
223
|
sequence.value = 0;
|
|
223
224
|
}
|
|
@@ -246,16 +247,16 @@ const useUpdated = (effectAction, dependencies = () => []) => {
|
|
|
246
247
|
upS.value += 1;
|
|
247
248
|
};
|
|
248
249
|
const runUpdatedQueueFromWDom = (newWDom) => {
|
|
249
|
-
const {
|
|
250
|
-
if (
|
|
251
|
-
const component = componentRef.get(
|
|
250
|
+
const { compKey } = newWDom;
|
|
251
|
+
if (compKey) {
|
|
252
|
+
const component = componentRef.get(compKey);
|
|
252
253
|
const queue = component == null ? void 0 : component.upCB;
|
|
253
254
|
const sequence = component == null ? void 0 : component.upS;
|
|
254
|
-
|
|
255
|
+
compKeyRef.value = compKey;
|
|
255
256
|
if (sequence) {
|
|
256
257
|
sequence.value = 0;
|
|
257
258
|
}
|
|
258
|
-
if (newWDom.
|
|
259
|
+
if (newWDom.ctor && queue) {
|
|
259
260
|
component.upCB = [];
|
|
260
261
|
queue.forEach((effect) => effect());
|
|
261
262
|
}
|
|
@@ -276,7 +277,7 @@ const render = (wDom, wrapElement, afterElement) => {
|
|
|
276
277
|
execMountedQueue();
|
|
277
278
|
return () => {
|
|
278
279
|
var _a;
|
|
279
|
-
const component = (_a = componentRef.get(wDom.
|
|
280
|
+
const component = (_a = componentRef.get(wDom.compProps || {})) == null ? void 0 : _a.vd.value;
|
|
280
281
|
if (component) {
|
|
281
282
|
runUnmountQueueFromWDom(component);
|
|
282
283
|
recursiveRemoveEvent(component);
|
|
@@ -415,16 +416,14 @@ const typeReplace = (newWDom) => {
|
|
|
415
416
|
}
|
|
416
417
|
};
|
|
417
418
|
const removeEvent = (oldProps, element) => {
|
|
418
|
-
|
|
419
|
-
(
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
);
|
|
425
|
-
}
|
|
419
|
+
entries(oldProps || {}).forEach(([dataKey, dataValue]) => {
|
|
420
|
+
if (dataKey.match(/^on/)) {
|
|
421
|
+
element.removeEventListener(
|
|
422
|
+
getEventName(dataKey),
|
|
423
|
+
dataValue
|
|
424
|
+
);
|
|
426
425
|
}
|
|
427
|
-
);
|
|
426
|
+
});
|
|
428
427
|
};
|
|
429
428
|
const typeUpdate = (newWDom) => {
|
|
430
429
|
var _a;
|
|
@@ -452,51 +451,49 @@ const updateText = (newWDom) => {
|
|
|
452
451
|
};
|
|
453
452
|
const updateProps = (props, element, oldProps) => {
|
|
454
453
|
const originalProps = { ...oldProps };
|
|
455
|
-
|
|
456
|
-
(
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
454
|
+
entries(props || {}).forEach(([dataKey, dataValue]) => {
|
|
455
|
+
if (dataKey === "key")
|
|
456
|
+
;
|
|
457
|
+
else if (dataKey === "innerHTML" && typeof dataValue === "string") {
|
|
458
|
+
element.innerHTML = dataValue;
|
|
459
|
+
} else if (checkStyleData(dataKey, dataValue)) {
|
|
460
|
+
updateStyle(
|
|
461
|
+
dataValue,
|
|
462
|
+
checkStyleData(dataKey, originalProps.style) ? originalProps.style : {},
|
|
463
|
+
element
|
|
464
|
+
);
|
|
465
|
+
} else if (checkRefData(dataKey, dataValue)) {
|
|
466
|
+
dataValue.value = element;
|
|
467
|
+
} else if (dataKey.match(/^on/)) {
|
|
468
|
+
updateEvent(
|
|
469
|
+
element,
|
|
470
|
+
dataKey,
|
|
471
|
+
dataValue,
|
|
472
|
+
originalProps[dataKey]
|
|
473
|
+
);
|
|
474
|
+
} else if (checkCheckableElement(element) && dataKey === "checked") {
|
|
475
|
+
element.checked = !!dataValue;
|
|
476
|
+
} else if (checkTextareaElement(element) && dataKey === "value") {
|
|
477
|
+
element.value = dataValue;
|
|
478
|
+
} else if (checkOptionElement(element) && dataKey === "selected") {
|
|
479
|
+
element.selected = !!dataValue;
|
|
480
|
+
} else if (checkNormalAttribute(dataValue)) {
|
|
481
|
+
if (xmlnsRef.value && dataKey !== "xmlns") {
|
|
482
|
+
element.setAttributeNS(
|
|
483
|
+
null,
|
|
484
|
+
getAttrKey(dataKey),
|
|
485
|
+
String(dataValue)
|
|
466
486
|
);
|
|
467
|
-
} else
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
element,
|
|
472
|
-
dataKey,
|
|
473
|
-
dataValue,
|
|
474
|
-
originalProps[dataKey]
|
|
487
|
+
} else {
|
|
488
|
+
element.setAttribute(
|
|
489
|
+
getAttrKey(dataKey),
|
|
490
|
+
String(dataValue)
|
|
475
491
|
);
|
|
476
|
-
} else if (checkCheckableElement(element) && dataKey === "checked") {
|
|
477
|
-
element.checked = !!dataValue;
|
|
478
|
-
} else if (checkTextareaElement(element) && dataKey === "value") {
|
|
479
|
-
element.value = dataValue;
|
|
480
|
-
} else if (checkOptionElement(element) && dataKey === "selected") {
|
|
481
|
-
element.selected = !!dataValue;
|
|
482
|
-
} else if (checkNormalAttribute(dataValue)) {
|
|
483
|
-
if (xmlnsRef.value && dataKey !== "xmlns") {
|
|
484
|
-
element.setAttributeNS(
|
|
485
|
-
null,
|
|
486
|
-
getAttrKey(dataKey),
|
|
487
|
-
String(dataValue)
|
|
488
|
-
);
|
|
489
|
-
} else {
|
|
490
|
-
element.setAttribute(
|
|
491
|
-
getAttrKey(dataKey),
|
|
492
|
-
String(dataValue)
|
|
493
|
-
);
|
|
494
|
-
}
|
|
495
492
|
}
|
|
496
|
-
delete originalProps[dataKey];
|
|
497
493
|
}
|
|
498
|
-
|
|
499
|
-
|
|
494
|
+
delete originalProps[dataKey];
|
|
495
|
+
});
|
|
496
|
+
keys(originalProps).forEach(
|
|
500
497
|
(dataKey) => element.removeAttribute(dataKey)
|
|
501
498
|
);
|
|
502
499
|
};
|
|
@@ -554,11 +551,11 @@ const updateStyle = (style, oldStyle, element) => {
|
|
|
554
551
|
const originalStyle = { ...oldStyle };
|
|
555
552
|
const elementStyle = element == null ? void 0 : element.style;
|
|
556
553
|
if (elementStyle) {
|
|
557
|
-
|
|
554
|
+
entries(style).forEach(([styleKey, dataValue]) => {
|
|
558
555
|
elementStyle[styleKey] = dataValue;
|
|
559
556
|
delete originalStyle[styleKey];
|
|
560
557
|
});
|
|
561
|
-
|
|
558
|
+
entries(originalStyle).forEach(
|
|
562
559
|
([styleKey]) => elementStyle[styleKey] = ""
|
|
563
560
|
);
|
|
564
561
|
}
|
|
@@ -580,29 +577,29 @@ const makeNewWDomTree = (newWDom, originalWDom) => remakeNewWDom(
|
|
|
580
577
|
);
|
|
581
578
|
const remakeNewWDom = (newWDom, isSameType, originalWDom) => {
|
|
582
579
|
const remakeWDom = generalize(newWDom, isSameType, originalWDom);
|
|
583
|
-
|
|
584
|
-
remakeWDom,
|
|
585
|
-
isSameType,
|
|
586
|
-
originalWDom
|
|
587
|
-
);
|
|
588
|
-
const needRerender = addReRenderTypeProperty(
|
|
580
|
+
const param = [
|
|
589
581
|
remakeWDom,
|
|
590
582
|
isSameType,
|
|
591
583
|
originalWDom
|
|
592
|
-
|
|
584
|
+
];
|
|
585
|
+
const needRerender = addReRenderTypeProperty(...param);
|
|
586
|
+
remakeWDom.children = remakeChildrenForDiff(...param);
|
|
593
587
|
remakeWDom.needRerender = needRerender;
|
|
588
|
+
inheritPropForRender(remakeWDom, originalWDom, needRerender);
|
|
589
|
+
return remakeWDom;
|
|
590
|
+
};
|
|
591
|
+
const inheritPropForRender = (remakeWDom, originalWDom, needRerender) => {
|
|
594
592
|
if (needRerender !== "A" && originalWDom) {
|
|
595
593
|
remakeWDom.el = originalWDom.el;
|
|
596
594
|
}
|
|
597
595
|
if (needRerender && ["D", "R", "SR"].includes(needRerender)) {
|
|
598
|
-
if (originalWDom == null ? void 0 : originalWDom.
|
|
596
|
+
if (originalWDom == null ? void 0 : originalWDom.compKey) {
|
|
599
597
|
runUnmountQueueFromWDom(originalWDom);
|
|
600
598
|
recursiveRemoveEvent(originalWDom);
|
|
601
599
|
}
|
|
602
600
|
remakeWDom.oldChildren = originalWDom == null ? void 0 : originalWDom.children;
|
|
603
601
|
}
|
|
604
602
|
remakeWDom.oldProps = originalWDom == null ? void 0 : originalWDom.props;
|
|
605
|
-
return remakeWDom;
|
|
606
603
|
};
|
|
607
604
|
const addReRenderTypeProperty = (newWDom, isSameType, originalWDom) => {
|
|
608
605
|
const existOriginalWDom = originalWDom && originalWDom.type;
|
|
@@ -729,67 +726,63 @@ const reRenderCustomComponent = (tag, props, children, originalWDom) => {
|
|
|
729
726
|
};
|
|
730
727
|
const makeWDomResolver = (tag, props, children) => {
|
|
731
728
|
const tagName = tag.name;
|
|
732
|
-
const
|
|
733
|
-
const resolve = (
|
|
734
|
-
initMountHookState(
|
|
729
|
+
const ctor = tag;
|
|
730
|
+
const resolve = (compKey = props) => {
|
|
731
|
+
initMountHookState(compKey);
|
|
735
732
|
const component = tag(props, children);
|
|
736
|
-
const componentMaker = component(
|
|
737
|
-
componentRender(componentKey),
|
|
738
|
-
props,
|
|
739
|
-
children
|
|
740
|
-
);
|
|
733
|
+
const componentMaker = component(componentRender(compKey), props, children);
|
|
741
734
|
const customNode = makeCustomNode(
|
|
742
735
|
componentMaker,
|
|
743
|
-
|
|
736
|
+
compKey,
|
|
744
737
|
tag,
|
|
745
738
|
props,
|
|
746
739
|
children
|
|
747
740
|
);
|
|
748
741
|
const originalWDom = customNode;
|
|
749
742
|
setRedrawAction(
|
|
750
|
-
|
|
743
|
+
compKey,
|
|
751
744
|
() => reRenderCustomComponent(tag, props, children, originalWDom)
|
|
752
745
|
);
|
|
753
|
-
getComponentSubInfo(
|
|
746
|
+
getComponentSubInfo(compKey, "vd").value = customNode;
|
|
754
747
|
return customNode;
|
|
755
748
|
};
|
|
756
|
-
return { tagName,
|
|
749
|
+
return { tagName, ctor, props, children, resolve };
|
|
757
750
|
};
|
|
758
|
-
const makeCustomNode = (componentMaker,
|
|
751
|
+
const makeCustomNode = (componentMaker, compKey, tag, props, children) => {
|
|
759
752
|
const customNode = componentMaker(props);
|
|
760
753
|
addComponentProps(
|
|
761
754
|
customNode,
|
|
762
|
-
|
|
755
|
+
compKey,
|
|
763
756
|
tag,
|
|
764
757
|
props,
|
|
765
758
|
children,
|
|
766
|
-
makeReRender(componentMaker,
|
|
759
|
+
makeReRender(componentMaker, compKey, tag, props, children)
|
|
767
760
|
);
|
|
768
761
|
return customNode;
|
|
769
762
|
};
|
|
770
|
-
const makeReRender = (componentMaker,
|
|
771
|
-
const reRender2 = () => wDomMaker(componentMaker,
|
|
763
|
+
const makeReRender = (componentMaker, compKey, tag, props, children) => {
|
|
764
|
+
const reRender2 = () => wDomMaker(componentMaker, compKey, tag, props, children, reRender2);
|
|
772
765
|
return reRender2;
|
|
773
766
|
};
|
|
774
|
-
const wDomMaker = (componentMaker,
|
|
775
|
-
initUpdateHookState(
|
|
767
|
+
const wDomMaker = (componentMaker, compKey, tag, props, children, reRender2) => {
|
|
768
|
+
initUpdateHookState(compKey);
|
|
776
769
|
runUpdateCallback();
|
|
777
770
|
const originalWDom = componentMaker(props);
|
|
778
771
|
setRedrawAction(
|
|
779
|
-
|
|
772
|
+
compKey,
|
|
780
773
|
() => reRenderCustomComponent(tag, props, children, originalWDom)
|
|
781
774
|
);
|
|
782
|
-
addComponentProps(originalWDom,
|
|
783
|
-
getComponentSubInfo(
|
|
775
|
+
addComponentProps(originalWDom, compKey, tag, props, children, reRender2);
|
|
776
|
+
getComponentSubInfo(compKey, "vd").value = originalWDom;
|
|
784
777
|
return originalWDom;
|
|
785
778
|
};
|
|
786
|
-
const addComponentProps = (wDom,
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
779
|
+
const addComponentProps = (wDom, compKey, tag, props, children, reRender2) => {
|
|
780
|
+
assign(wDom, {
|
|
781
|
+
compProps: props,
|
|
782
|
+
compChild: children,
|
|
783
|
+
ctor: tag,
|
|
791
784
|
tagName: tag.name,
|
|
792
|
-
|
|
785
|
+
compKey,
|
|
793
786
|
reRender: reRender2
|
|
794
787
|
});
|
|
795
788
|
};
|