functions in attributes

pull/1864/head
Rich Harris 7 years ago
parent fba0f58226
commit a18ef98ca1

@ -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,

@ -7,7 +7,7 @@
}
function toggle() {
currentIdentifier = isCurrentlySelected ? null : identifier
currentIdentifier = isCurrentlySelected() ? null : identifier
}
</script>

@ -1,4 +1,6 @@
export default {
solo: 1,
html: `
<p><span class=''>1</span></p>
<p><span class='selected'>2</span></p>
@ -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 {
<p><span class='selected'>1</span></p>
`);
spans[0].dispatchEvent(click);
await spans[0].dispatchEvent(click);
assert.equal(component.currentIdentifier, null);
assert.htmlEqual(target.innerHTML, `

Loading…
Cancel
Save