From 8750545f334753d569b62a26479502464b337b64 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Sat, 1 Oct 2022 11:44:39 -0400 Subject: [PATCH] var should recompute when child compute is dirty (#173) * Remove commented code * var should recompute when child compute is dirty * Adding a changeset --- .changeset/pretty-ducks-chew.md | 5 +++++ src/each.js | 10 ---------- src/value.js | 4 +++- test/test-store.js | 15 +++++++++++++++ test/test-var.js | 14 ++++++++++++++ 5 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 .changeset/pretty-ducks-chew.md diff --git a/.changeset/pretty-ducks-chew.md b/.changeset/pretty-ducks-chew.md new file mode 100644 index 0000000..ac77cf1 --- /dev/null +++ b/.changeset/pretty-ducks-chew.md @@ -0,0 +1,5 @@ +--- +"corset": patch +--- + +var should recompute when child compute is dirty diff --git a/src/each.js b/src/each.js index 2182619..d6d4244 100644 --- a/src/each.js +++ b/src/each.js @@ -68,17 +68,7 @@ export class EachInstance { let e = /** @type {HTMLElement} */(element); addItemToScope(e, eachSymbol, 'item', itemSymbol, 'corsetScope', value); addItemToScope(e, eachSymbol, 'index', indexSymbol, 'corsetScope', index); - - // /** @type {HTMLElement} */ - // (element).dataset[itemProp] = ''; - // /** @type {any} */ - // (element)[Symbol.for(itemProp)] = value; - // /** @type {HTMLElement} */ - // (element).dataset[indexProp] = ''; - // /** @type {any} */ - // (element)[Symbol.for(indexProp)] = index; } - } } /** diff --git a/src/value.js b/src/value.js index 33bd45c..0b2e9f5 100644 --- a/src/value.js +++ b/src/value.js @@ -104,8 +104,10 @@ export class PlaceholderValue { this.compute = scope.compute; this.value = scope.value; return true; + } else if(this.compute !== NO_VALUE) { + return this.compute.dirty(changeset); } else { - // Nothing has changed. + // Nothing has changed return false; } } else if(args.length > 1) { diff --git a/test/test-store.js b/test/test-store.js index 9678ff1..a1a0d8e 100644 --- a/test/test-store.js +++ b/test/test-store.js @@ -186,4 +186,19 @@ QUnit.test('Store is immediate available in child behavior', assert => { next(); assert.equal(el.className, 'resolved'); assert.equal(el.textContent, 'Resolved'); +}); + +QUnit.test('Can be used to set vars', assert => { + let root = document.createElement('main'); + root.innerHTML = `
`; + sheet` + #app { + store-root: app; + store-set: app first "Wilbur"; + + --full-name: store-get(app, first) " " "Phillips"; + text: var(--full-name); + } + `.update(root); + assert.equal(root.firstElementChild.textContent, 'Wilbur Phillips'); }); \ No newline at end of file diff --git a/test/test-var.js b/test/test-var.js index 67360eb..a7fb761 100644 --- a/test/test-var.js +++ b/test/test-var.js @@ -31,4 +31,18 @@ QUnit.test('Can pass multiple values to a property', assert => { assert.equal(lis[i].querySelector('.color').textContent, colorName); i++; } +}); + +QUnit.test('Can pass multiple values to text', assert => { + let root = document.createElement('main'); + root.innerHTML = `
`; + sheet` + #app { + --first: "Wilbur"; + --last: "Phillips"; + --full-name: var(--first) " " var(--last); + text: var(--full-name); + } + `.update(root); + assert.equal(root.firstElementChild.textContent, 'Wilbur Phillips'); }); \ No newline at end of file