Skip to content

Commit

Permalink
var should recompute when child compute is dirty (#173)
Browse files Browse the repository at this point in the history
* Remove commented code

* var should recompute when child compute is dirty

* Adding a changeset
  • Loading branch information
matthewp authored Oct 1, 2022
1 parent baf6ea6 commit 8750545
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/pretty-ducks-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"corset": patch
---

var should recompute when child compute is dirty
10 changes: 0 additions & 10 deletions src/each.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
}
/**
Expand Down
4 changes: 3 additions & 1 deletion src/value.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
15 changes: 15 additions & 0 deletions test/test-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `<div id="app"></div>`;
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');
});
14 changes: 14 additions & 0 deletions test/test-var.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `<div id="app"></div>`;
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');
});

0 comments on commit 8750545

Please sign in to comment.