@snupo/jmc 1.0.50 → 1.0.52

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/jmc.js CHANGED
@@ -36,10 +36,10 @@ let removeexcesschildren = (n, i) => {
36
36
  let syncchildren = (p, cn, i, depth, uc) => {
37
37
  cn.flat(999)
38
38
  .filter(hc => hc !== null && hc !== undefined) // skip. keep 0 and false renderable, per comment below)
39
- .forEach(hc => (i = sync(p, i, hc, depth, uc)));
39
+ .forEach(hc => (i = sync(p, i, hc, undefined, depth, uc)));
40
40
  return i;
41
41
  };
42
- function sync(parent, i, h, depth, uc) {
42
+ function sync(parent, i, h, hfun, depth, uc) {
43
43
  // console.log('%csync2', "background:orange", parent.tagName, i, h, depth)
44
44
  if (h === null || h === undefined)
45
45
  return i; // skip. keep 0 and false renderable, per comment below
@@ -52,8 +52,8 @@ function sync(parent, i, h, depth, uc) {
52
52
  cn ??= [];
53
53
  let process = () => {
54
54
  setprops(n, n.h?.p, p);
55
- n.h = h; // sets the new property values
56
- if (--depth && !n.h?.p?.const && !iswebcomponent(h)) {
55
+ n.h = hfun ?? h; // sets the new property values
56
+ if (--depth && !n.hasAttribute('const') && !iswebcomponent(h)) {
57
57
  const j = syncchildren(n, cn, 0, depth, uc);
58
58
  removeexcesschildren(n, j);
59
59
  }
@@ -80,11 +80,7 @@ function sync(parent, i, h, depth, uc) {
80
80
  case 2:
81
81
  {
82
82
  let hr = h.tag(h.p, h.cn);
83
- let j = sync(parent, i, hr, depth, uc);
84
- let n = parent.childNodes[i]; // now the dom element exists, unless the function returned undefined or null
85
- if (n)
86
- n.h = h;
87
- return j;
83
+ return sync(parent, i, hr, hfun ?? h, depth, uc);
88
84
  }
89
85
  case 3: {
90
86
  let isupdate = c?.h?.tag == h.tag;
@@ -92,14 +88,17 @@ function sync(parent, i, h, depth, uc) {
92
88
  let ci = c.h.i;
93
89
  ci.props = h.p;
94
90
  // update() substitutes view/sync when returning truthy
95
- return (ci.update?.(uc)) ? i + 1 : sync(parent, i, ci.view(), depth, uc);
91
+ return (ci.update?.(uc)) ? i + 1 : sync(parent, i, ci.view(), hfun ?? h, depth, uc); // hfun because outermost function shall be attached
96
92
  }
97
93
  let ci = h.i = rebind(new h.tag(h.p));
98
- let j = sync(parent, i, ci.view(), depth, uc);
94
+ let hv = ci.view();
95
+ let j = sync(parent, i, hv, h, depth, uc);
99
96
  let n = parent.childNodes[i];
100
97
  ci.element = n;
101
- n.h = h;
102
- ci.mounted?.();
98
+ if (hv) {
99
+ n.h = h;
100
+ ci.mounted?.();
101
+ }
103
102
  return j;
104
103
  }
105
104
  default:
@@ -124,7 +123,7 @@ export function patch(e, h, depth = 999, uc = {}) {
124
123
  }
125
124
  let p = e.parentElement;
126
125
  let i = [].indexOf.call(p.childNodes, e);
127
- sync(p, i, h, depth, uc);
126
+ sync(p, i, h, undefined, depth, uc);
128
127
  }
129
128
  export function updateview(...cmds) {
130
129
  if (!cmds.length)
package/dist/jmc.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"jmc.js","sourceRoot":"","sources":["../src/jmc.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAYlC,IAAI,cAAc,GAAG,CAAC,CAAW,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;AAEzD,MAAM,UAAU,GAAG,CAAC,CAAU,EAAE,IAAY,EAAE,KAAU,EAAE,EAAE,CACxD,IAAI,KAAK,SAAS;IAClB,CAAC,KAAK,YAAY,MAAM;QACpB,KAAK,YAAY,QAAQ;QACzB,CAAC,CAAC,CAAC,YAAY,KAAK,4BAA4B,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,OAAO,CAAC,CAAC,CAAA;AAE1F,IAAI,QAAQ,GAAG,CAAC,CAAc,EAAE,GAAkB,EAAE,GAAkB,EAAE,EAAE;IAEtE,GAAG,KAAK,EA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AAE,CAAC;gBACxB,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;YACxC,CAAC;iBAAM,IAAI,CAAC,YAAY,IAAI,EAAE,CAAC;gBAC3B,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;oBACN,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,CAAA;oBACxB,UAAU,EAAE,CAAA;gBAChB,CAAC;YACL,CAAC;iBAAM,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;gBAC/B,KAAK,GAAG,CAAC,CAAA;YACb,CAAC;iBAAM,CAAC;gBACJ,EAAE,GAAG,CAAC,CAAA;YACV,CAAC;QACL,CAAC;IACL,CAAC;IAED,CAAC,CAAC,IAAI,CAAC,CAAA;IAEP,IAAI,CAAC,UAAU;QAAE,OAAO,CAAC,IAAI,CAAC,2CAA2C,EAAE,GAAG,IAAI,CAAC,CAAA;AACvF,CAAC","sourcesContent":["import type { H, HElement, J, Selector, Children, HClassComponent, HU } from './h'\r\nimport { rebind } from './base.js'\r\n\r\nconst enum NodeType { // vaporizes (but for that must be in this file, otherwise not)\r\n TextNode = 3\r\n}\r\n\r\ndeclare global {\r\n interface Node {\r\n h?: H & { p?: J }\r\n }\r\n}\r\n\r\nlet iswebcomponent = (h: HElement) => h.tag.includes('-')\r\n\r\nconst isproperty = (e: Element, name: string, value: any) =>\r\n name !== \"viewBox\" &&\r\n (value instanceof Object ||\r\n value instanceof Function ||\r\n (e.namespaceURI !== \"http://www.w3.org/2000/svg\" && name in e && name != 'style'))\r\n\r\nlet setprops = (e: Element & J, old: J | undefined, now: J | undefined) => {\r\n\r\n old ??= {}\r\n now ??= {}\r\n\r\n // removals\r\n for (let p in old)\r\n if (!(p in now))\r\n isproperty(e, p, old[p])\r\n ? e[p] = typeof old[p] === 'boolean' ? false : ''\r\n : e.removeAttribute(p)\r\n // updates\r\n for (let p in now) {\r\n let v = now[p]\r\n if (v != old[p]) {\r\n isproperty(e, p, v)\r\n ? e[p] = v\r\n : e.setAttribute(p, v)\r\n }\r\n }\r\n}\r\n\r\nlet removeexcesschildren = (n: Element, i: number) => {\r\n let c: ChildNode\r\n while ((c = n.childNodes[i])) {\r\n try { c.remove() } catch (_) { } // due to blur-event-handlers, this can fail\r\n }\r\n}\r\n\r\n/** synchronizes children starting at the i-th element. returns the index of the last child synchronized */\r\nlet syncchildren = (p: Element, cn: Children, i: number, depth: number, uc: J): number => {\r\n cn.flat(999)\r\n .filter(hc => hc !== null && hc !== undefined) // skip. keep 0 and false renderable, per comment below)\r\n .forEach(hc => (i = sync(p, i, hc, depth, uc)))\r\n return i\r\n}\r\n\r\nfunction sync(parent: Element, i: number, h: HU, depth: number, uc: J): number {\r\n\r\n // console.log('%csync2', \"background:orange\", parent.tagName, i, h, depth)\r\n\r\n if (h === null || h === undefined) return i // skip. keep 0 and false renderable, per comment below\r\n\r\n let c = parent.childNodes[i]\r\n\r\n switch (h.kind) {\r\n case 1:\r\n {\r\n let n: Element\r\n let { tag, cn, p } = h\r\n cn ??= []\r\n\r\n let process = () => {\r\n setprops(n, n.h?.p, p)\r\n n.h = h // sets the new property values\r\n\r\n if (--depth && !n.h?.p?.const && !iswebcomponent(h as HElement)) {\r\n const j = syncchildren(n, cn, 0, depth, uc)\r\n removeexcesschildren(n, j)\r\n }\r\n }\r\n\r\n if ((<Element>c)?.tagName?.toLowerCase() != tag.toLowerCase()) {\r\n let ns = p?.xmlns ?? (parent.tagName == \"foreignObject\" ? 'http://www.w3.org/1999/xhtml' : parent.namespaceURI)\r\n n = document.createElementNS(ns, tag)\r\n c ? c.replaceWith(n) : parent.appendChild(n)\r\n process()\r\n p?.mounted?.(n)\r\n } else {\r\n n = c as Element\r\n process()\r\n if (p?.update?.(c, uc)) return i + 1\r\n }\r\n\r\n return i + 1\r\n }\r\n\r\n case 4:\r\n {\r\n return syncchildren(parent, h.cn ?? [], i, --depth, uc)\r\n }\r\n\r\n case 2:\r\n {\r\n let hr = h.tag(h.p, h.cn)\r\n let j = sync(parent, i, hr, depth, uc)\r\n let n = parent.childNodes[i]! // now the dom element exists, unless the function returned undefined or null\r\n if (n) n.h = h\r\n return j\r\n }\r\n\r\n case 3: {\r\n let isupdate = (c?.h as any)?.tag == h.tag\r\n\r\n if (isupdate) {\r\n let ci = (c!.h as HClassComponent).i!\r\n ci.props = h.p\r\n\r\n // update() substitutes view/sync when returning truthy\r\n return (ci.update?.(uc)) ? i + 1 : sync(parent, i, ci.view(), depth, uc)\r\n }\r\n\r\n let ci = h.i = rebind(new h.tag(h.p))\r\n let j = sync(parent, i, ci.view(), depth, uc)\r\n let n = parent.childNodes[i]!\r\n ci.element = n\r\n n.h = h\r\n ci.mounted?.()\r\n return j\r\n }\r\n\r\n default:\r\n // textnode\r\n let s = h.toString()\r\n if (c?.nodeType == NodeType.TextNode) {\r\n if (c.textContent != s) c.textContent = s // firefox updates equal text, loosing existing text selection\r\n } else {\r\n c ? c.replaceWith(s) : parent.append(s)\r\n }\r\n return i + 1\r\n }\r\n}\r\n\r\nexport function patch(e: Node | null, h: H, depth = 999, uc = {} as J) {\r\n if (!e) return\r\n if (depth == 0) {\r\n (e as HTMLElement).replaceChildren()\r\n depth = 999\r\n }\r\n let p = e.parentElement as HTMLElement\r\n let i = [].indexOf.call<any, any, any>(p.childNodes, e)\r\n sync(p, i, h, depth, uc)\r\n}\r\n\r\nexport type Command = Selector | J | number\r\n\r\nexport function updateview(...cmds: Command[]): void {\r\n\r\n if (!cmds.length) cmds.push('body')\r\n let uc = {}\r\n let depth = 999\r\n let patchcount = 0\r\n\r\n function f(cmds: Command[]) {\r\n for (const c of cmds) {\r\n if (typeof c === 'string') {\r\n f([...document.querySelectorAll(c)])\r\n } else if (c instanceof Node) {\r\n if (c.h) {\r\n patch(c, c.h, depth, uc)\r\n patchcount++\r\n }\r\n } else if (typeof c === 'number') {\r\n depth = c\r\n } else {\r\n uc = c\r\n }\r\n }\r\n }\r\n\r\n f(cmds)\r\n\r\n if (!patchcount) console.warn(\"updateview did not update anything. cmds=\", ...cmds)\r\n}\r\n"]}
1
+ {"version":3,"file":"jmc.js","sourceRoot":"","sources":["../src/jmc.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAYlC,IAAI,cAAc,GAAG,CAAC,CAAW,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;AAEzD,MAAM,UAAU,GAAG,CAAC,CAAU,EAAE,IAAY,EAAE,KAAU,EAAE,EAAE,CACxD,IAAI,KAAK,SAAS;IAClB,CAAC,KAAK,YAAY,MAAM;QACpB,KAAK,YAAY,QAAQ;QACzB,CAAC,CAAC,CAAC,YAAY,KAAK,4BAA4B,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,OAAO,CAAC,CAAC,CAAA;AAE1F,IAAI,QAAQ,GAAG,CAAC,CAAc,EAAE,GAAkB,EAAE,GAAkB,EAAE,EAAE;IAEtE,GAAG,KAAK,EAAE,CAAA;IACV,GAAG,KAAK,EAAE,CAAA;IAEV,WAAW;IACX,KAAK,IAAI,CAAC,IAAI,GAAG;QACb,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC;YACX,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;gBACpB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;gBACjD,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAA;IAClC,UAAU;IACV,KAAK,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAA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C,CAAA;IAEP,IAAI,CAAC,UAAU;QAAE,OAAO,CAAC,IAAI,CAAC,2CAA2C,EAAE,GAAG,IAAI,CAAC,CAAA;AACvF,CAAC","sourcesContent":["import type { H, HElement, J, Selector, Children, HClassComponent, HU } from './h'\r\nimport { rebind } from './base.js'\r\n\r\nconst enum NodeType { // vaporizes (but for that must be in this file, otherwise not)\r\n TextNode = 3\r\n}\r\n\r\ndeclare global {\r\n interface Node {\r\n h?: H & { p?: J }\r\n }\r\n}\r\n\r\nlet iswebcomponent = (h: HElement) => h.tag.includes('-')\r\n\r\nconst isproperty = (e: Element, name: string, value: any) =>\r\n name !== \"viewBox\" &&\r\n (value instanceof Object ||\r\n value instanceof Function ||\r\n (e.namespaceURI !== \"http://www.w3.org/2000/svg\" && name in e && name != 'style'))\r\n\r\nlet setprops = (e: Element & J, old: J | undefined, now: J | undefined) => {\r\n\r\n old ??= {}\r\n now ??= {}\r\n\r\n // removals\r\n for (let p in old)\r\n if (!(p in now))\r\n isproperty(e, p, old[p])\r\n ? e[p] = typeof old[p] === 'boolean' ? false : ''\r\n : e.removeAttribute(p)\r\n // updates\r\n for (let p in now) {\r\n let v = now[p]\r\n if (v != old[p]) {\r\n isproperty(e, p, v)\r\n ? e[p] = v\r\n : e.setAttribute(p, v)\r\n }\r\n }\r\n}\r\n\r\nlet removeexcesschildren = (n: Element, i: number) => {\r\n let c: ChildNode\r\n while ((c = n.childNodes[i])) {\r\n try { c.remove() } catch (_) { } // due to blur-event-handlers, this can fail\r\n }\r\n}\r\n\r\n/** synchronizes children starting at the i-th element. returns the index of the last child synchronized */\r\nlet syncchildren = (p: Element, cn: Children, i: number, depth: number, uc: J): number => {\r\n cn.flat(999)\r\n .filter(hc => hc !== null && hc !== undefined) // skip. keep 0 and false renderable, per comment below)\r\n .forEach(hc => (i = sync(p, i, hc, undefined, depth, uc)))\r\n return i\r\n}\r\n\r\nfunction sync(parent: Element, i: number, h: HU, hfun: H | undefined, depth: number, uc: J): number {\r\n\r\n // console.log('%csync2', \"background:orange\", parent.tagName, i, h, depth)\r\n\r\n if (h === null || h === undefined) return i // skip. keep 0 and false renderable, per comment below\r\n\r\n let c = parent.childNodes[i]\r\n\r\n switch (h.kind) {\r\n case 1:\r\n {\r\n let n: Element\r\n let { tag, cn, p } = h\r\n cn ??= []\r\n\r\n let process = () => {\r\n setprops(n, n.h?.p, p)\r\n n.h = hfun ?? h // sets the new property values\r\n\r\n if (--depth && !n.hasAttribute('const') && !iswebcomponent(h as HElement)) {\r\n const j = syncchildren(n, cn, 0, depth, uc)\r\n removeexcesschildren(n, j)\r\n }\r\n }\r\n\r\n if ((<Element>c)?.tagName?.toLowerCase() != tag.toLowerCase()) {\r\n let ns = p?.xmlns ?? (parent.tagName == \"foreignObject\" ? 'http://www.w3.org/1999/xhtml' : parent.namespaceURI)\r\n n = document.createElementNS(ns, tag)\r\n c ? c.replaceWith(n) : parent.appendChild(n)\r\n process()\r\n p?.mounted?.(n)\r\n } else {\r\n n = c as Element\r\n process()\r\n if (p?.update?.(c, uc)) return i + 1\r\n }\r\n\r\n return i + 1\r\n }\r\n\r\n case 4:\r\n {\r\n return syncchildren(parent, h.cn ?? [], i, --depth, uc)\r\n }\r\n\r\n case 2:\r\n {\r\n let hr = h.tag(h.p, h.cn)\r\n return sync(parent, i, hr, hfun ?? h, depth, uc)\r\n }\r\n\r\n case 3: {\r\n let isupdate = (c?.h as any)?.tag == h.tag\r\n\r\n if (isupdate) {\r\n let ci = (c!.h as HClassComponent).i!\r\n ci.props = h.p\r\n\r\n // update() substitutes view/sync when returning truthy\r\n return (ci.update?.(uc)) ? i + 1 : sync(parent, i, ci.view(), hfun ?? h, depth, uc) // hfun because outermost function shall be attached\r\n }\r\n\r\n let ci = h.i = rebind(new h.tag(h.p))\r\n let hv = ci.view()\r\n let j = sync(parent, i, hv, h, depth, uc)\r\n let n = parent.childNodes[i]!\r\n ci.element = n\r\n if (hv) {\r\n n.h = h\r\n ci.mounted?.()\r\n }\r\n return j\r\n }\r\n\r\n default:\r\n // textnode\r\n let s = h.toString()\r\n if (c?.nodeType == NodeType.TextNode) {\r\n if (c.textContent != s) c.textContent = s // firefox updates equal text, loosing existing text selection\r\n } else {\r\n c ? c.replaceWith(s) : parent.append(s)\r\n }\r\n return i + 1\r\n }\r\n}\r\n\r\nexport function patch(e: Node | null, h: H, depth = 999, uc = {} as J) {\r\n if (!e) return\r\n if (depth == 0) {\r\n (e as HTMLElement).replaceChildren()\r\n depth = 999\r\n }\r\n let p = e.parentElement as HTMLElement\r\n let i = [].indexOf.call<any, any, any>(p.childNodes, e)\r\n sync(p, i, h, undefined, depth, uc)\r\n}\r\n\r\nexport type Command = Selector | J | number\r\n\r\nexport function updateview(...cmds: Command[]): void {\r\n\r\n if (!cmds.length) cmds.push('body')\r\n let uc = {}\r\n let depth = 999\r\n let patchcount = 0\r\n\r\n function f(cmds: Command[]) {\r\n for (const c of cmds) {\r\n if (typeof c === 'string') {\r\n f([...document.querySelectorAll(c)])\r\n } else if (c instanceof Node) {\r\n if (c.h) {\r\n patch(c, c.h, depth, uc)\r\n patchcount++\r\n }\r\n } else if (typeof c === 'number') {\r\n depth = c\r\n } else {\r\n uc = c\r\n }\r\n }\r\n }\r\n\r\n f(cmds)\r\n\r\n if (!patchcount) console.warn(\"updateview did not update anything. cmds=\", ...cmds)\r\n}\r\n"]}
package/package.json CHANGED
@@ -1,48 +1,48 @@
1
- {
2
- "name": "@snupo/jmc",
3
- "author": "snupo",
4
- "version": "1.0.50",
5
- "publishConfig": {
6
- "access": "public"
7
- },
8
- "type": "module",
9
- "main": "./dist/index.js",
10
- "types": "./dist/index.d.ts",
11
- "exports": {
12
- ".": {
13
- "types": "./dist/index.d.ts",
14
- "import": "./dist/index.js"
15
- }
16
- },
17
- "files": [
18
- "dist",
19
- "src"
20
- ],
21
- "scripts": {
22
- "prebuild": "rimraf dist",
23
- "build": "tsc -p tsconfig.json",
24
- "release": "release-it patch"
25
- },
26
- "devDependencies": {
27
- "@vitest/coverage-v8": "^4.1.10",
28
- "happy-dom": "^16.8.1",
29
- "release-it": "^21.0.2",
30
- "rimraf": "^6.1.3",
31
- "typescript": "^6.0.3",
32
- "vitest": "4.1.10"
33
- },
34
- "release-it": {
35
- "hooks": {
36
- "before:init": [
37
- "pnpm vitest"
38
- ],
39
- "after:bump": "pnpm build"
40
- },
41
- "git": {
42
- "commitMessage": "chore: release v${version}"
43
- },
44
- "github": {
45
- "release": true
46
- }
47
- }
48
- }
1
+ {
2
+ "name": "@snupo/jmc",
3
+ "author": "snupo",
4
+ "version": "1.0.52",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "type": "module",
9
+ "main": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "src"
20
+ ],
21
+ "scripts": {
22
+ "prebuild": "rimraf dist",
23
+ "build": "tsc -p tsconfig.json",
24
+ "release": "release-it patch"
25
+ },
26
+ "devDependencies": {
27
+ "@vitest/coverage-v8": "^4.1.10",
28
+ "happy-dom": "^16.8.1",
29
+ "release-it": "^21.0.2",
30
+ "rimraf": "^6.1.3",
31
+ "typescript": "^6.0.3",
32
+ "vitest": "4.1.10"
33
+ },
34
+ "release-it": {
35
+ "hooks": {
36
+ "before:init": [
37
+ "pnpm vitest"
38
+ ],
39
+ "after:bump": "pnpm build"
40
+ },
41
+ "git": {
42
+ "commitMessage": "chore: release v${version}"
43
+ },
44
+ "github": {
45
+ "release": true
46
+ }
47
+ }
48
+ }
package/src/jmc.ts CHANGED
@@ -52,11 +52,11 @@ let removeexcesschildren = (n: Element, i: number) => {
52
52
  let syncchildren = (p: Element, cn: Children, i: number, depth: number, uc: J): number => {
53
53
  cn.flat(999)
54
54
  .filter(hc => hc !== null && hc !== undefined) // skip. keep 0 and false renderable, per comment below)
55
- .forEach(hc => (i = sync(p, i, hc, depth, uc)))
55
+ .forEach(hc => (i = sync(p, i, hc, undefined, depth, uc)))
56
56
  return i
57
57
  }
58
58
 
59
- function sync(parent: Element, i: number, h: HU, depth: number, uc: J): number {
59
+ function sync(parent: Element, i: number, h: HU, hfun: H | undefined, depth: number, uc: J): number {
60
60
 
61
61
  // console.log('%csync2', "background:orange", parent.tagName, i, h, depth)
62
62
 
@@ -73,9 +73,9 @@ function sync(parent: Element, i: number, h: HU, depth: number, uc: J): number {
73
73
 
74
74
  let process = () => {
75
75
  setprops(n, n.h?.p, p)
76
- n.h = h // sets the new property values
76
+ n.h = hfun ?? h // sets the new property values
77
77
 
78
- if (--depth && !n.h?.p?.const && !iswebcomponent(h as HElement)) {
78
+ if (--depth && !n.hasAttribute('const') && !iswebcomponent(h as HElement)) {
79
79
  const j = syncchildren(n, cn, 0, depth, uc)
80
80
  removeexcesschildren(n, j)
81
81
  }
@@ -104,10 +104,7 @@ function sync(parent: Element, i: number, h: HU, depth: number, uc: J): number {
104
104
  case 2:
105
105
  {
106
106
  let hr = h.tag(h.p, h.cn)
107
- let j = sync(parent, i, hr, depth, uc)
108
- let n = parent.childNodes[i]! // now the dom element exists, unless the function returned undefined or null
109
- if (n) n.h = h
110
- return j
107
+ return sync(parent, i, hr, hfun ?? h, depth, uc)
111
108
  }
112
109
 
113
110
  case 3: {
@@ -118,15 +115,18 @@ function sync(parent: Element, i: number, h: HU, depth: number, uc: J): number {
118
115
  ci.props = h.p
119
116
 
120
117
  // update() substitutes view/sync when returning truthy
121
- return (ci.update?.(uc)) ? i + 1 : sync(parent, i, ci.view(), depth, uc)
118
+ return (ci.update?.(uc)) ? i + 1 : sync(parent, i, ci.view(), hfun ?? h, depth, uc) // hfun because outermost function shall be attached
122
119
  }
123
120
 
124
121
  let ci = h.i = rebind(new h.tag(h.p))
125
- let j = sync(parent, i, ci.view(), depth, uc)
122
+ let hv = ci.view()
123
+ let j = sync(parent, i, hv, h, depth, uc)
126
124
  let n = parent.childNodes[i]!
127
125
  ci.element = n
128
- n.h = h
129
- ci.mounted?.()
126
+ if (hv) {
127
+ n.h = h
128
+ ci.mounted?.()
129
+ }
130
130
  return j
131
131
  }
132
132
 
@@ -150,7 +150,7 @@ export function patch(e: Node | null, h: H, depth = 999, uc = {} as J) {
150
150
  }
151
151
  let p = e.parentElement as HTMLElement
152
152
  let i = [].indexOf.call<any, any, any>(p.childNodes, e)
153
- sync(p, i, h, depth, uc)
153
+ sync(p, i, h, undefined, depth, uc)
154
154
  }
155
155
 
156
156
  export type Command = Selector | J | number