foldkit 0.46.0 → 0.46.1
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/propsModule.d.ts.map +1 -1
- package/dist/propsModule.js +16 -16
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"propsModule.d.ts","sourceRoot":"","sources":["../src/propsModule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"propsModule.d.ts","sourceRoot":"","sources":["../src/propsModule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AA0DtC,eAAO,MAAM,WAAW,EAAE,MAAqD,CAAA"}
|
package/dist/propsModule.js
CHANGED
|
@@ -7,34 +7,33 @@
|
|
|
7
7
|
* Since a disabled button swallows click events at the browser level, an
|
|
8
8
|
* `OnClick` handler that replaces `Disabled` at the same index silently fails.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
|
|
10
|
+
* Instead of relying on the old vnode's `data.props` for cleanup (which
|
|
11
|
+
* requires snabbdom to patch rather than recreate), this module tracks which
|
|
12
|
+
* properties it has set on each DOM element via a WeakMap. On every create or
|
|
13
|
+
* update hook, it compares the tracked set against the new vnode's props and
|
|
14
|
+
* resets anything that was removed to its type-appropriate default: booleans →
|
|
15
|
+
* false, strings → '', numbers → 0. The WeakMap entries are garbage-collected
|
|
16
|
+
* when the element is removed from the DOM. */
|
|
17
|
+
const managedProps = new WeakMap();
|
|
18
|
+
function updateProps(_oldVnode, vnode) {
|
|
14
19
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
15
20
|
const elm = vnode.elm;
|
|
16
21
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (!oldProps && !props) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
if (oldProps === props) {
|
|
22
|
+
const props = (vnode.data?.props ?? {});
|
|
23
|
+
const previous = managedProps.get(elm) ?? {};
|
|
24
|
+
if (props === previous) {
|
|
24
25
|
return;
|
|
25
26
|
}
|
|
26
|
-
oldProps = oldProps ?? {};
|
|
27
|
-
props = props ?? {};
|
|
28
27
|
for (const key in props) {
|
|
29
28
|
const cur = props[key];
|
|
30
|
-
const old =
|
|
29
|
+
const old = previous[key];
|
|
31
30
|
if (old !== cur && (key !== 'value' || elm[key] !== cur)) {
|
|
32
31
|
elm[key] = cur;
|
|
33
32
|
}
|
|
34
33
|
}
|
|
35
|
-
for (const key in
|
|
34
|
+
for (const key in previous) {
|
|
36
35
|
if (!(key in props)) {
|
|
37
|
-
const old =
|
|
36
|
+
const old = previous[key];
|
|
38
37
|
if (typeof old === 'boolean') {
|
|
39
38
|
elm[key] = false;
|
|
40
39
|
}
|
|
@@ -46,5 +45,6 @@ function updateProps(oldVnode, vnode) {
|
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
47
|
}
|
|
48
|
+
managedProps.set(elm, { ...props });
|
|
49
49
|
}
|
|
50
50
|
export const propsModule = { create: updateProps, update: updateProps };
|