Skip to content

Commit 7da9a23

Browse files
committed
put component methods on prototype
1 parent c1e82f6 commit 7da9a23

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

src/generators/dom/index.js

+18-20
Original file line numberDiff line numberDiff line change
@@ -291,42 +291,40 @@ export default function dom ( parsed, source, options, names ) {
291291
292292
this._handlers = Object.create( null );
293293
294-
this.get = get;
295-
this.fire = fire;
296-
this.observe = observe;
297-
this.on = on;
298-
this.set = set;
299-
this.teardown = teardown;
300-
301294
this._root = options._root;
302295
this._yield = options._yield;
303296
304297
${builders.init}
305298
}
299+
` );
300+
301+
if ( templateProperties.methods ) {
302+
builders.main.addBlock( `${name}.prototype = template.methods;` );
303+
}
304+
305+
builders.main.addBlock( deindent`
306+
${name}.prototype.get = ${shared.get};
307+
308+
${name}.prototype.fire = ${shared.fire};
306309
307-
function set ( newState ) {
310+
${name}.prototype.observe = ${shared.observe};
311+
312+
${name}.prototype.on = ${shared.on};
313+
314+
${name}.prototype.set = function set ( newState ) {
308315
${builders.set}
309-
}
316+
};
310317
311-
function teardown ( detach ) {
318+
${name}.prototype.teardown = function teardown ( detach ) {
312319
this.fire( 'teardown' );${templateProperties.onteardown ? `\ntemplate.onteardown.call( this );` : ``}
313320
314321
this._fragment.teardown( detach !== false );
315322
this._fragment = null;
316323
317324
this._state = {};
318-
}
325+
};
319326
` );
320327

321-
if ( templateProperties.methods ) {
322-
builders.main.addBlock( `${name}.prototype = template.methods;` );
323-
}
324-
325-
builders.main.addBlock( shared.fire.toString() );
326-
builders.main.addBlock( shared.get.toString() );
327-
builders.main.addBlock( shared.observe.toString() );
328-
builders.main.addBlock( shared.on.toString() );
329-
330328
builders.main.addBlock( shared.dispatchObservers.toString() );
331329

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

0 commit comments

Comments
 (0)