diff --git a/compiler/generate/index.js b/compiler/generate/index.js index 5e8e23bde3..b2fa544450 100644 --- a/compiler/generate/index.js +++ b/compiler/generate/index.js @@ -617,11 +617,17 @@ export default function generate ( parsed, template ) { mainFragment = null; state = {}; + + ${templateProperties.onteardown ? `template.onteardown.call( component );` : ``} }; + ${templateProperties.oninit ? `template.oninit.call( component );` : ``} + let mainFragment = renderMainFragment( component, options.target ); component.set( ${templateProperties.data ? `Object.assign( template.data(), options.data )` : `options.data`} ); + ${templateProperties.onrender ? `template.onrender.call( component );` : ``} + return component; } `; diff --git a/test/compiler/lifecycle-events/_config.js b/test/compiler/lifecycle-events/_config.js new file mode 100644 index 0000000000..ae13dd2e2c --- /dev/null +++ b/test/compiler/lifecycle-events/_config.js @@ -0,0 +1,9 @@ +import * as assert from 'assert'; + +export default { + test ( component ) { + assert.deepEqual( component.events, [ 'init', 'render' ]); + component.teardown(); + assert.deepEqual( component.events, [ 'init', 'render', 'teardown' ]); + } +}; diff --git a/test/compiler/lifecycle-events/main.svelte b/test/compiler/lifecycle-events/main.svelte new file mode 100644 index 0000000000..dc56c8e27a --- /dev/null +++ b/test/compiler/lifecycle-events/main.svelte @@ -0,0 +1,17 @@ +
+ +