diff --git a/src/compile/render-dom/wrappers/Element/index.ts b/src/compile/render-dom/wrappers/Element/index.ts index 88e991d846..83647953b4 100644 --- a/src/compile/render-dom/wrappers/Element/index.ts +++ b/src/compile/render-dom/wrappers/Element/index.ts @@ -163,6 +163,17 @@ export default class ElementWrapper extends Wrapper { block.addAnimation(); } + // add directive and handler dependencies + [node.animation, node.outro, ...node.actions, ...node.classes].forEach(directive => { + if (directive && directive.expression) { + block.addDependencies(directive.expression.dependencies); + } + }); + + node.handlers.forEach(handler => { + block.addDependencies(handler.dependencies); + }); + if (this.parent) { if (node.actions.length > 0) this.parent.cannotUseInnerHTML(); if (node.animation) this.parent.cannotUseInnerHTML(); @@ -394,20 +405,6 @@ export default class ElementWrapper extends Wrapper { : `{}`}, ${this.node.namespace === namespaces.svg ? true : false})`; } - // addBindings(block: Block) { - // if (this.bindings.length === 0) return; - - // if (this.node.name === 'select' || this.isMediaNode()) { - // this.renderer.hasComplexBindings = true; - // } - - // this.bindings.forEach(binding => { - // binding.render(block); - // }); - - // this.initialUpdate = this.bindings.map(binding => binding.initialUpdate).filter(Boolean).join('\n'); - // } - addBindings(block: Block) { const { renderer } = this; diff --git a/src/compile/render-ssr/handlers/Element.ts b/src/compile/render-ssr/handlers/Element.ts index 00ff1ba980..5aec6fb6b5 100644 --- a/src/compile/render-ssr/handlers/Element.ts +++ b/src/compile/render-ssr/handlers/Element.ts @@ -105,7 +105,7 @@ export default function(node, renderer, options) { openingTag += '${' + attribute.chunks[0].snippet + ' ? " ' + attribute.name + '" : "" }'; } else if (attribute.name === 'class' && classExpr) { addClassAttribute = false; - openingTag += ` class="\${ [\`${attribute.stringifyForSsr()}\`, ${classExpr} ].join(' ').trim() }"`; + openingTag += ` class="\${[\`${attribute.stringifyForSsr()}\`, ${classExpr}].join(' ').trim() }"`; } else { openingTag += ` ${attribute.name}="${attribute.stringifyForSsr()}"`; } @@ -113,7 +113,7 @@ export default function(node, renderer, options) { } if (addClassAttribute) { - openingTag += ` class="\${ [${classExpr}].join(' ').trim() }"`; + openingTag += `\${((v) => v ? ' class="' + v + '"' : '')([${classExpr}].join(' ').trim())}`; } openingTag += '>'; diff --git a/test/runtime/samples/class-in-each/_config.js b/test/runtime/samples/class-in-each/_config.js new file mode 100644 index 0000000000..124c162e7e --- /dev/null +++ b/test/runtime/samples/class-in-each/_config.js @@ -0,0 +1,21 @@ +export default { + data: { + things: ['one', 'two', 'three'], + selected: 'two' + }, + + html: ` +
+
+
+ `, + + test(assert, component, target) { + component.set({ selected: 'three' }); + assert.htmlEqual(target.innerHTML, ` +
+
+
+ `); + } +}; diff --git a/test/runtime/samples/class-in-each/main.html b/test/runtime/samples/class-in-each/main.html new file mode 100644 index 0000000000..7b822fa313 --- /dev/null +++ b/test/runtime/samples/class-in-each/main.html @@ -0,0 +1,3 @@ +{#each things as thing} +
+{/each} diff --git a/test/runtime/samples/event-handler-each-context/_config.js b/test/runtime/samples/event-handler-each-context/_config.js new file mode 100644 index 0000000000..73358545d3 --- /dev/null +++ b/test/runtime/samples/event-handler-each-context/_config.js @@ -0,0 +1,21 @@ +export default { + data: { + items: [ + 'whatever' + ], + foo: 'wrong', + bar: 'right' + }, + + test(assert, component, target, window) { + const button = target.querySelector('button'); + const event = new window.MouseEvent('click'); + + button.dispatchEvent(event); + assert.equal(component.get().foo, 'right'); + + component.set({ bar: 'left' }); + button.dispatchEvent(event); + assert.equal(component.get().foo, 'left'); + } +}; diff --git a/test/runtime/samples/event-handler-each-context/main.html b/test/runtime/samples/event-handler-each-context/main.html new file mode 100644 index 0000000000..830bbce47e --- /dev/null +++ b/test/runtime/samples/event-handler-each-context/main.html @@ -0,0 +1,5 @@ +{#each items as item} + +{/each} + +

foo: {foo}

\ No newline at end of file