Skip to content

Commit

Permalink
put component methods on prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Dec 20, 2016
1 parent c1e82f6 commit 7da9a23
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions src/generators/dom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,42 +291,40 @@ export default function dom ( parsed, source, options, names ) {
this._handlers = Object.create( null );
this.get = get;
this.fire = fire;
this.observe = observe;
this.on = on;
this.set = set;
this.teardown = teardown;
this._root = options._root;
this._yield = options._yield;
${builders.init}
}
` );

if ( templateProperties.methods ) {
builders.main.addBlock( `${name}.prototype = template.methods;` );
}

builders.main.addBlock( deindent`
${name}.prototype.get = ${shared.get};
${name}.prototype.fire = ${shared.fire};
function set ( newState ) {
${name}.prototype.observe = ${shared.observe};
${name}.prototype.on = ${shared.on};
${name}.prototype.set = function set ( newState ) {
${builders.set}
}
};
function teardown ( detach ) {
${name}.prototype.teardown = function teardown ( detach ) {
this.fire( 'teardown' );${templateProperties.onteardown ? `\ntemplate.onteardown.call( this );` : ``}
this._fragment.teardown( detach !== false );
this._fragment = null;
this._state = {};
}
};
` );

if ( templateProperties.methods ) {
builders.main.addBlock( `${name}.prototype = template.methods;` );
}

builders.main.addBlock( shared.fire.toString() );
builders.main.addBlock( shared.get.toString() );
builders.main.addBlock( shared.observe.toString() );
builders.main.addBlock( shared.on.toString() );

builders.main.addBlock( shared.dispatchObservers.toString() );

Object.keys( generator.uses ).forEach( key => {
Expand Down

0 comments on commit 7da9a23

Please sign in to comment.