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.
@@ -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;AAyDtC,eAAO,MAAM,WAAW,EAAE,MAAqD,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"}
@@ -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
- * This module adds a second loop (mirroring what snabbdom's attributesModule
11
- * already does) that resets removed props to type-appropriate defaults:
12
- * booleans false, strings '', numbers 0. */
13
- function updateProps(oldVnode, vnode) {
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
- let oldProps = oldVnode.data?.props;
18
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
19
- let props = vnode.data?.props;
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 = oldProps[key];
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 oldProps) {
34
+ for (const key in previous) {
36
35
  if (!(key in props)) {
37
- const old = oldProps[key];
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foldkit",
3
- "version": "0.46.0",
3
+ "version": "0.46.1",
4
4
  "description": "A frontend framework for TypeScript, built on Effect, using The Elm Architecture",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",