From a18ef98ca186c098d63bd8561cb0bbbabd66396d Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Fri, 23 Nov 2018 22:58:04 -0500 Subject: [PATCH] functions in attributes --- src/compile/render-dom/wrappers/Element/Attribute.ts | 10 ++++++---- .../samples/component-binding-infinite-loop/C.html | 2 +- .../samples/component-binding-infinite-loop/_config.js | 6 ++++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/compile/render-dom/wrappers/Element/Attribute.ts b/src/compile/render-dom/wrappers/Element/Attribute.ts index 07e3f495da..33a91b3361 100644 --- a/src/compile/render-dom/wrappers/Element/Attribute.ts +++ b/src/compile/render-dom/wrappers/Element/Attribute.ts @@ -99,7 +99,7 @@ export default class AttributeWrapper { const isSelectValueAttribute = name === 'value' && element.node.name === 'select'; - const shouldCache = !this.node.dependencies.has('$$BAIL$$') && (this.node.shouldCache || isSelectValueAttribute); + const shouldCache = (this.node.shouldCache || isSelectValueAttribute); const last = shouldCache && block.getUniqueName( `${element.var}_${name.replace(/[^a-zA-Z_$]/g, '_')}_value` @@ -168,9 +168,11 @@ export default class AttributeWrapper { const updateCachedValue = `${last} !== (${last} = ${value})`; - const condition = shouldCache ? - ( dependencies.length ? `(${changedCheck}) && ${updateCachedValue}` : updateCachedValue ) : - changedCheck; + const condition = this.node.dependencies.has('$$BAIL$$') + ? updateCachedValue + : shouldCache + ? (dependencies.length ? `(${changedCheck}) && ${updateCachedValue}` : updateCachedValue) + : changedCheck; block.builders.update.addConditional( condition, diff --git a/test/runtime/samples/component-binding-infinite-loop/C.html b/test/runtime/samples/component-binding-infinite-loop/C.html index 44a94bfd5a..a8074ae07c 100644 --- a/test/runtime/samples/component-binding-infinite-loop/C.html +++ b/test/runtime/samples/component-binding-infinite-loop/C.html @@ -7,7 +7,7 @@ } function toggle() { - currentIdentifier = isCurrentlySelected ? null : identifier + currentIdentifier = isCurrentlySelected() ? null : identifier } diff --git a/test/runtime/samples/component-binding-infinite-loop/_config.js b/test/runtime/samples/component-binding-infinite-loop/_config.js index e29321f697..e9643d3ec1 100644 --- a/test/runtime/samples/component-binding-infinite-loop/_config.js +++ b/test/runtime/samples/component-binding-infinite-loop/_config.js @@ -1,4 +1,6 @@ export default { + solo: 1, + html: `

1

2

@@ -29,7 +31,7 @@ export default { const click = new window.MouseEvent('click'); const spans = target.querySelectorAll('span'); - spans[0].dispatchEvent(click); + await spans[0].dispatchEvent(click); assert.equal(component.currentIdentifier, 1); assert.htmlEqual(target.innerHTML, ` @@ -58,7 +60,7 @@ export default {

1

`); - spans[0].dispatchEvent(click); + await spans[0].dispatchEvent(click); assert.equal(component.currentIdentifier, null); assert.htmlEqual(target.innerHTML, `