@sola-air-ui/compiler 1.5.2 → 1.5.3

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +13 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sola-air-ui/compiler",
3
- "version": "1.5.2",
3
+ "version": "1.5.3",
4
4
  "description": "Compiler for Sola single-file components (.sola) \u2014 transforms template + script + style to ES modules",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/index.js CHANGED
@@ -1504,12 +1504,24 @@ export function compile(source, options = {}) {
1504
1504
  domCode += ` const _key = String(${keyExpr});\n`;
1505
1505
  domCode += ` _seen.add(_key);\n`;
1506
1506
  domCode += ` let _entry = ${eid}_keyMap.get(_key);\n`;
1507
+ // A row's bindings read the item it was built with. When the list hands
1508
+ // back a different object for the same key (an immutable update such as
1509
+ // items.map(i => i.id === id ? { ...i, done: true } : i)), or the index the
1510
+ // row shows has changed, rebuild that row; rows whose item is the same
1511
+ // object are kept as they are.
1512
+ domCode += ` if (_entry && (_entry.item !== ${node.attribs.item}${node.attribs.index ? ` || _entry.index !== _i` : ''})) {\n`;
1513
+ domCode += ` __flush_destroys(_entry.ctx);\n`;
1514
+ domCode += ` const _old = _entry.nodes;\n`;
1515
+ domCode += ` if (_old.includes(_cursor)) _cursor = _old[_old.length - 1].nextSibling;\n`;
1516
+ domCode += ` _old.forEach(n => n.remove());\n`;
1517
+ domCode += ` _entry = null;\n`;
1518
+ domCode += ` }\n`;
1507
1519
  domCode += ` if (!_entry) {\n`;
1508
1520
  domCode += ` const _kctx = pushContext();\n`;
1509
1521
  domCode += ` try {\n`;
1510
1522
  domCode += ` const f = document.createDocumentFragment();\n`;
1511
1523
  node.children.forEach(child => emitNode(child, 'f', eachLocals, inSvg));
1512
- domCode += ` _entry = { nodes: Array.from(f.childNodes), ctx: _kctx };\n`;
1524
+ domCode += ` _entry = { nodes: Array.from(f.childNodes), ctx: _kctx, item: ${node.attribs.item}${node.attribs.index ? ', index: _i' : ''} };\n`;
1513
1525
  domCode += ` } finally { popContext(_kctx); }\n`;
1514
1526
  domCode += ` ${eid}_keyMap.set(_key, _entry);\n`;
1515
1527
  domCode += ` }\n`;