Fixes #668 - Events handler in the include tag

This commit is contained in:
Patrick Steele-Idem 2017-04-12 21:16:18 -06:00
parent de0c491fc6
commit 0a0430ab7d
6 changed files with 36 additions and 8 deletions

View File

@ -52,8 +52,6 @@ module.exports = function handleComponentBind() {
let context = this.context;
let builder = this.builder;
let internalBindAttr = el.getAttribute('_componentbind');
let componentModule;
let rendererModulePath;
let rendererModule = this.getRendererModule();
@ -119,9 +117,7 @@ module.exports = function handleComponentBind() {
true /* computed */)
]));
}
} else if (internalBindAttr != null) {
el.removeAttribute('_componentbind');
} else if (el.isFlagSet('hasComponentBind')) {
componentModule = this.getComponentModule();
rendererModulePath = this.getRendererModule();

View File

@ -255,7 +255,7 @@ module.exports = function handleRootNodes() {
var nextKey = 0;
rootNodes.forEach((curNode, i) => {
curNode.setAttributeValue('_componentbind');
curNode.setFlag('hasComponentBind');
if (!curNode.hasAttribute('key') && !curNode.hasAttribute('ref')) {
if (curNode.type === 'CustomTag' || rootNodes.length > 1) {

View File

@ -45,6 +45,7 @@ module.exports = function transform(el, context) {
if (el.tagName === 'widget-types') {
context.setFlag('hasWidgetTypes');
} else if (el.tagName === 'include') {
transformHelper.handleComponentEvents();
transformHelper.handleIncludeNode(el);
transformHelper.getComponentArgs().compile(transformHelper);
return;
@ -55,8 +56,7 @@ module.exports = function transform(el, context) {
return;
}
if (el.hasAttribute('_componentbind') || el.hasAttribute('w-bind')) {
el.setFlag('hasComponentBind');
if (el.isFlagSet('hasComponentBind') || el.hasAttribute('w-bind')) {
transformHelper.handleComponentBind();
}

View File

@ -0,0 +1,6 @@
class {
}
<button type="button" on-click('emit', 'hello')>
Say hello
</button>

View File

@ -0,0 +1,15 @@
import helloComponent from './components/hello.marko';
class {
onCreate() {
this.helloReceived = false;
}
handleHello() {
this.helloReceived = true;
}
}
<div>
<include(helloComponent) on-hello('handleHello')/>
</div>

View File

@ -0,0 +1,11 @@
var expect = require('chai').expect;
module.exports = function(helpers) {
var component = helpers.mount(require('./index'), { });
expect(component.helloReceived).to.equal(false);
component.el.querySelector('button').click();
expect(component.helloReceived).to.equal(true);
};