allow conditionally binding to different roots in a legacy widget (#944)

This commit is contained in:
Michael Rawlings 2017-12-07 12:02:05 -06:00 committed by GitHub
parent 3dacde72aa
commit 62ddb65fa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 5 deletions

View File

@ -6,14 +6,14 @@ var FLAG_HAS_BODY_EL = 2;
var FLAG_HAS_HEAD_EL = 4;
module.exports = function handleComponentBind(options) {
if (this.firstBind) {
let context = this.context;
let builder = this.builder;
if (this.context.firstBind) {
return;
}
this.firstBind = true;
let context = this.context;
let builder = this.builder;
context.firstBind = true;
let isLegacyComponent = this.isLegacyComponent = options.isLegacyComponent === true;
let componentModule = options.componentModule;

View File

@ -0,0 +1,13 @@
module.exports = require('marko/legacy-components').defineComponent({
template: require('./template.marko'),
getInitialState: function(input) {
return { interactive:input.interactive }
},
getTemplateData: function (state, input) {
return {
interactive: state.interactive
};
}
});

View File

@ -0,0 +1,8 @@
<if(data.interactive)>
<button w-bind>
Interactive
</button>
</if>
<else>
<div w-bind>Non-interactive</div>
</else>

View File

@ -0,0 +1,14 @@
var expect = require('chai').expect;
module.exports = function (helpers) {
var widget = helpers.mount(require('./index'), {
interactive: true
});
expect(widget.el).to.be.instanceOf(HTMLButtonElement);
widget.setState('interactive', false);
widget.update();
expect(widget.el).to.be.instanceOf(HTMLDivElement);
};