diff --git a/.changeset/small-shrimps-walk.md b/.changeset/small-shrimps-walk.md new file mode 100644 index 0000000..21a30c1 --- /dev/null +++ b/.changeset/small-shrimps-walk.md @@ -0,0 +1,5 @@ +--- +"corset": patch +--- + +Update when pushing to an empty array using longhand each diff --git a/src/multi-binding.js b/src/multi-binding.js index edf8c47..cec808c 100644 --- a/src/multi-binding.js +++ b/src/multi-binding.js @@ -280,7 +280,7 @@ export class MultiBinding extends Binding { // Fill in the defaults by looking at the valueMap for holes. for(let [key, values] of valueMap) { - if(!dirtyKeys.has(key)) continue; + let isDirty = dirtyKeys.has(key); // valueMap is always appended from a longhand prop. let numOfValues = this.numberOfValues; let keyed = this.defn.feat & features.keyed; @@ -298,7 +298,7 @@ export class MultiBinding extends Binding { values.push(...current); } } - yield [/** @type {[K, ...any[]]} */(/** @type {unknown} */(values)), true]; + yield [/** @type {[K, ...any[]]} */(/** @type {unknown} */(values)), isDirty]; } // Yield out to reset to initial state. diff --git a/test/test-each.js b/test/test-each.js index fbeec82..77e2cf5 100644 --- a/test/test-each.js +++ b/test/test-each.js @@ -140,4 +140,29 @@ QUnit.test('Changes to items result in updates', assert => { bind().update(root); assert.equal(ul.firstElementChild.textContent, 'one'); assert.equal(ul.firstElementChild.nextElementSibling.textContent, 'two !!'); +}); + +QUnit.test('Pushing to an empty list (longhand)', assert => { + let root = document.createElement('main'); + root.innerHTML = ``; + let items = []; + function bind() { + return sheet` + ul { + each-items: ${items}; + each-template: select(template); + } + + li { + text: get(item(), label); + } + `; + } + let ul = root.firstElementChild; + bind().update(root); + + items.push({ label: 'works' }); + bind().update(root); + assert.equal(ul.children.length, 1); + assert.equal(ul.firstElementChild.textContent, 'works'); }); \ No newline at end of file