diff --git a/index.js b/index.js index 4691d20dee..8eb1b4f805 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,7 @@ -import { onprops, onmount, onupdate, ondestroy, createEventDispatcher } from './internal.js'; - -export { onprops, onmount, onupdate, ondestroy, createEventDispatcher }; \ No newline at end of file +export { + onMount, + onDestroy, + beforeRender, + afterRender, + createEventDispatcher +} from './internal.js'; \ No newline at end of file diff --git a/src/Stats.ts b/src/Stats.ts index 5e60db4d3c..a1c9d3571b 100644 --- a/src/Stats.ts +++ b/src/Stats.ts @@ -99,9 +99,9 @@ export default class Stats { // TODO const hooks: Record = component && { oncreate: false, - ondestroy: false, + onDestroy: false, onstate: false, - onupdate: false + afterRender: false }; return { diff --git a/src/internal/Component.js b/src/internal/Component.js index 84924d57b6..c30731e4ec 100644 --- a/src/internal/Component.js +++ b/src/internal/Component.js @@ -5,10 +5,10 @@ import { blankObject } from './utils.js'; export class $$Component { constructor(options) { - this.$$onprops = []; - this.$$onmount = []; - this.$$onupdate = []; - this.$$ondestroy = []; + this.$$beforeRender = []; + this.$$onMount = []; + this.$$afterRender = []; + this.$$onDestroy = []; this.$$bindings = blankObject(); this.$$callbacks = blankObject(); @@ -60,8 +60,6 @@ export class $$Component { $set(values) { if (this.$$) { this.$$.inject_props(values); - run_all(this.$$onprops); // TODO should this be deferred until the update? - for (const key in values) this.$$make_dirty(key); } } @@ -74,10 +72,10 @@ export class $$Component { $$destroy(detach) { if (this.$$) { this.$$fragment.d(detach); - run_all(this.$$ondestroy); + run_all(this.$$onDestroy); // TODO null out other refs - this.$$ondestroy = this.$$fragment = this.$$ = null; + this.$$onDestroy = this.$$fragment = this.$$ = null; } } @@ -90,19 +88,21 @@ export class $$Component { } $$mount(target, anchor) { + run_all(this.$$beforeRender); this.$$fragment.c(); this.$$fragment[this.$$fragment.i ? 'i' : 'm'](target, anchor); this.$$.inject_refs(this.$$refs); - const ondestroy = this.$$onmount.map(fn => fn()).filter(Boolean); - this.$$ondestroy.push(...ondestroy); - this.$$onmount = []; + const onDestroy = this.$$onMount.map(fn => fn()).filter(Boolean); + this.$$onDestroy.push(...onDestroy); + this.$$onMount = []; } $$update() { + run_all(this.$$beforeRender); this.$$fragment.p(this.$$dirty, this.$$.get_state()); this.$$.inject_refs(this.$$refs); - run_all(this.$$onupdate); + run_all(this.$$afterRender); this.$$dirty = null; } } diff --git a/src/internal/await-block.js b/src/internal/await-block.js index 7f0bc5154f..18f18946df 100644 --- a/src/internal/await-block.js +++ b/src/internal/await-block.js @@ -33,7 +33,7 @@ export function handlePromise(promise, info) { // TODO is some of this redundant? info.component.$$.inject_refs(info.component.$$refs); - run_all(info.component.$$onupdate); + run_all(info.component.$$afterRender); flush(); } diff --git a/src/internal/lifecycle.js b/src/internal/lifecycle.js index 0232ef9c3d..df39b84f94 100644 --- a/src/internal/lifecycle.js +++ b/src/internal/lifecycle.js @@ -4,20 +4,20 @@ export function set_current_component(component) { current_component = component; } -export function onprops(fn) { - current_component.$$onprops.push(fn); +export function beforeRender(fn) { + current_component.$$beforeRender.push(fn); } -export function onmount(fn) { - current_component.$$onmount.push(fn); +export function onMount(fn) { + current_component.$$onMount.push(fn); } -export function onupdate(fn) { - current_component.$$onupdate.push(fn); +export function afterRender(fn) { + current_component.$$afterRender.push(fn); } -export function ondestroy(fn) { - current_component.$$ondestroy.push(fn); +export function onDestroy(fn) { + current_component.$$onDestroy.push(fn); } export function createEventDispatcher() { diff --git a/test/cli/samples/sourcemap-inline/src/Main.html b/test/cli/samples/sourcemap-inline/src/Main.html index ad51c3d3d0..6f3f80bbff 100644 --- a/test/cli/samples/sourcemap-inline/src/Main.html +++ b/test/cli/samples/sourcemap-inline/src/Main.html @@ -1,7 +1,7 @@ diff --git a/test/cli/samples/sourcemap/src/Main.html b/test/cli/samples/sourcemap/src/Main.html index ad51c3d3d0..6f3f80bbff 100644 --- a/test/cli/samples/sourcemap/src/Main.html +++ b/test/cli/samples/sourcemap/src/Main.html @@ -1,7 +1,7 @@ diff --git a/test/custom-elements/samples/oncreate/main.html b/test/custom-elements/samples/oncreate/main.html index 7854aeec02..1a521ed761 100644 --- a/test/custom-elements/samples/oncreate/main.html +++ b/test/custom-elements/samples/oncreate/main.html @@ -1,11 +1,11 @@ diff --git a/test/js/samples/deconflict-globals/input.html b/test/js/samples/deconflict-globals/input.html index b0760d27fe..4e0b72d2d1 100644 --- a/test/js/samples/deconflict-globals/input.html +++ b/test/js/samples/deconflict-globals/input.html @@ -1,9 +1,9 @@ \ No newline at end of file diff --git a/test/js/samples/ssr-no-oncreate-etc/input.html b/test/js/samples/ssr-no-oncreate-etc/input.html index 845c4797bd..1e8fff7de1 100644 --- a/test/js/samples/ssr-no-oncreate-etc/input.html +++ b/test/js/samples/ssr-no-oncreate-etc/input.html @@ -5,14 +5,14 @@ diff --git a/test/runtime/samples/bindings-before-oncreate/One.html b/test/runtime/samples/bindings-before-oncreate/One.html index 54c771e32f..fa8b885de3 100644 --- a/test/runtime/samples/bindings-before-oncreate/One.html +++ b/test/runtime/samples/bindings-before-oncreate/One.html @@ -1,11 +1,11 @@ diff --git a/test/runtime/samples/component-binding-blowback-b/Nested.html b/test/runtime/samples/component-binding-blowback-b/Nested.html index 58c689ce7f..b69bc2ac8a 100644 --- a/test/runtime/samples/component-binding-blowback-b/Nested.html +++ b/test/runtime/samples/component-binding-blowback-b/Nested.html @@ -1,5 +1,5 @@ diff --git a/test/runtime/samples/component-binding-blowback-c/Nested.html b/test/runtime/samples/component-binding-blowback-c/Nested.html index 901d5f3a67..03ec136470 100644 --- a/test/runtime/samples/component-binding-blowback-c/Nested.html +++ b/test/runtime/samples/component-binding-blowback-c/Nested.html @@ -1,5 +1,5 @@ diff --git a/test/runtime/samples/component-binding-deep-b/main.html b/test/runtime/samples/component-binding-deep-b/main.html index a9d88e1885..577aa16b2e 100644 --- a/test/runtime/samples/component-binding-deep-b/main.html +++ b/test/runtime/samples/component-binding-deep-b/main.html @@ -1,5 +1,5 @@ diff --git a/test/runtime/samples/flush-before-bindings/Visibility.html b/test/runtime/samples/flush-before-bindings/Visibility.html index 98ce02f2b8..fa2a88f93b 100644 --- a/test/runtime/samples/flush-before-bindings/Visibility.html +++ b/test/runtime/samples/flush-before-bindings/Visibility.html @@ -1,9 +1,9 @@ diff --git a/test/runtime/samples/flush-before-bindings/main.html b/test/runtime/samples/flush-before-bindings/main.html index 8d2428704f..446cd8c102 100644 --- a/test/runtime/samples/flush-before-bindings/main.html +++ b/test/runtime/samples/flush-before-bindings/main.html @@ -1,11 +1,11 @@ diff --git a/test/runtime/samples/observe-deferred/main.html b/test/runtime/samples/observe-deferred/main.html index ab80973fb2..310606b182 100644 --- a/test/runtime/samples/observe-deferred/main.html +++ b/test/runtime/samples/observe-deferred/main.html @@ -1,12 +1,12 @@ diff --git a/test/runtime/samples/oncreate-async-arrow-block/main.html b/test/runtime/samples/oncreate-async-arrow-block/main.html index 4b075b09a4..f75c6ccd4e 100644 --- a/test/runtime/samples/oncreate-async-arrow-block/main.html +++ b/test/runtime/samples/oncreate-async-arrow-block/main.html @@ -1,7 +1,7 @@ diff --git a/test/runtime/samples/oncreate-async-arrow/main.html b/test/runtime/samples/oncreate-async-arrow/main.html index 67ec75056a..35ebde8ae2 100644 --- a/test/runtime/samples/oncreate-async-arrow/main.html +++ b/test/runtime/samples/oncreate-async-arrow/main.html @@ -1,5 +1,5 @@ diff --git a/test/runtime/samples/oncreate-async/main.html b/test/runtime/samples/oncreate-async/main.html index 4b075b09a4..f75c6ccd4e 100644 --- a/test/runtime/samples/oncreate-async/main.html +++ b/test/runtime/samples/oncreate-async/main.html @@ -1,7 +1,7 @@ diff --git a/test/runtime/samples/oncreate-sibling-order/Nested.html b/test/runtime/samples/oncreate-sibling-order/Nested.html index 958be20e68..6d93be98dc 100644 --- a/test/runtime/samples/oncreate-sibling-order/Nested.html +++ b/test/runtime/samples/oncreate-sibling-order/Nested.html @@ -1,11 +1,11 @@ diff --git a/test/runtime/samples/ondestroy-before-cleanup/Top.html b/test/runtime/samples/ondestroy-before-cleanup/Top.html index 1133a6eacf..7a023b75b6 100644 --- a/test/runtime/samples/ondestroy-before-cleanup/Top.html +++ b/test/runtime/samples/ondestroy-before-cleanup/Top.html @@ -1,10 +1,10 @@ diff --git a/test/runtime/samples/onrender-chain/Item.html b/test/runtime/samples/onrender-chain/Item.html index 34ccd9c33e..0317e153bc 100644 --- a/test/runtime/samples/onrender-chain/Item.html +++ b/test/runtime/samples/onrender-chain/Item.html @@ -1,10 +1,10 @@ diff --git a/test/runtime/samples/onrender-fires-when-ready-nested/Widget.html b/test/runtime/samples/onrender-fires-when-ready-nested/Widget.html index b6cb8c8a55..80c2dad6c5 100644 --- a/test/runtime/samples/onrender-fires-when-ready-nested/Widget.html +++ b/test/runtime/samples/onrender-fires-when-ready-nested/Widget.html @@ -1,11 +1,11 @@ diff --git a/test/runtime/samples/onrender-fires-when-ready/Widget.html b/test/runtime/samples/onrender-fires-when-ready/Widget.html index b6cb8c8a55..80c2dad6c5 100644 --- a/test/runtime/samples/onrender-fires-when-ready/Widget.html +++ b/test/runtime/samples/onrender-fires-when-ready/Widget.html @@ -1,11 +1,11 @@ diff --git a/test/runtime/samples/onstate-before-oncreate/main.html b/test/runtime/samples/onstate-before-oncreate/main.html index 657cab43d1..2093a1220c 100644 --- a/test/runtime/samples/onstate-before-oncreate/main.html +++ b/test/runtime/samples/onstate-before-oncreate/main.html @@ -1,20 +1,20 @@ diff --git a/test/runtime/samples/onstate/main.html b/test/runtime/samples/onstate/main.html index 054db485e0..9b5afa1c86 100644 --- a/test/runtime/samples/onstate/main.html +++ b/test/runtime/samples/onstate/main.html @@ -1,10 +1,10 @@ diff --git a/test/runtime/samples/onupdate/main.html b/test/runtime/samples/onupdate/main.html index ab80973fb2..310606b182 100644 --- a/test/runtime/samples/onupdate/main.html +++ b/test/runtime/samples/onupdate/main.html @@ -1,12 +1,12 @@ diff --git a/test/runtime/samples/options/main.html b/test/runtime/samples/options/main.html index e33a0ea223..30f6947a2c 100644 --- a/test/runtime/samples/options/main.html +++ b/test/runtime/samples/options/main.html @@ -1,9 +1,9 @@ diff --git a/test/runtime/samples/set-in-oncreate/main.html b/test/runtime/samples/set-in-oncreate/main.html index fb7f0cc5ad..66463c030a 100644 --- a/test/runtime/samples/set-in-oncreate/main.html +++ b/test/runtime/samples/set-in-oncreate/main.html @@ -1,9 +1,9 @@ diff --git a/test/runtime/samples/set-in-ondestroy/_config.js b/test/runtime/samples/set-in-ondestroy/_config.js deleted file mode 100644 index beb4522a9c..0000000000 --- a/test/runtime/samples/set-in-ondestroy/_config.js +++ /dev/null @@ -1,26 +0,0 @@ -export default { - 'skip-ssr': true, - - props: { - foo: 1 - }, - - test(assert, component) { - const values = []; - let valueOnDestroy; - - component.$on('destroy', () => { - component.foo = 2; - valueOnDestroy = component.foo; - }); - - component.$on('state', ({ current }) => { - values.push(current.foo); - }); - - component.$destroy(); - - assert.deepEqual(values, [2]); - assert.equal(valueOnDestroy, 2); - } -}; diff --git a/test/runtime/samples/set-in-ondestroy/main.html b/test/runtime/samples/set-in-ondestroy/main.html deleted file mode 100644 index c6cac69265..0000000000 --- a/test/runtime/samples/set-in-ondestroy/main.html +++ /dev/null @@ -1 +0,0 @@ -empty diff --git a/test/runtime/samples/set-in-onstate-dedupes-renders/Widget.html b/test/runtime/samples/set-in-onstate-dedupes-renders/Widget.html index 25900ca9a7..0745f0e068 100644 --- a/test/runtime/samples/set-in-onstate-dedupes-renders/Widget.html +++ b/test/runtime/samples/set-in-onstate-dedupes-renders/Widget.html @@ -1,10 +1,10 @@ diff --git a/test/runtime/samples/set-in-onstate/_config.js b/test/runtime/samples/set-in-onstate/_config.js index 816372ea00..7990401090 100644 --- a/test/runtime/samples/set-in-onstate/_config.js +++ b/test/runtime/samples/set-in-onstate/_config.js @@ -6,11 +6,11 @@ export default {

2

`, - test ( assert, component, target ) { + test(assert, component, target) { component.foo = 2; - assert.htmlEqual( target.innerHTML, ` + assert.htmlEqual(target.innerHTML, `

2

4

- ` ); + `); } }; diff --git a/test/runtime/samples/set-in-onstate/main.html b/test/runtime/samples/set-in-onstate/main.html index 8755a79e4f..a166d1a11b 100644 --- a/test/runtime/samples/set-in-onstate/main.html +++ b/test/runtime/samples/set-in-onstate/main.html @@ -1,10 +1,10 @@ diff --git a/test/runtime/samples/set-undefined-attr/main.html b/test/runtime/samples/set-undefined-attr/main.html index a4d96e012f..8191acbeff 100644 --- a/test/runtime/samples/set-undefined-attr/main.html +++ b/test/runtime/samples/set-undefined-attr/main.html @@ -1,10 +1,10 @@ diff --git a/test/runtime/samples/transition-js-events/main.html b/test/runtime/samples/transition-js-events/main.html index 15e99e56b9..c3f2fc90ed 100644 --- a/test/runtime/samples/transition-js-events/main.html +++ b/test/runtime/samples/transition-js-events/main.html @@ -2,7 +2,7 @@ Perhaps add on:introend etc on the elements? --> diff --git a/test/stats/samples/hooks/_config.js b/test/stats/samples/hooks/_config.js index 5778d44102..70830cf54d 100644 --- a/test/stats/samples/hooks/_config.js +++ b/test/stats/samples/hooks/_config.js @@ -2,9 +2,9 @@ export default { test(assert, stats) { assert.deepEqual(stats.hooks, { oncreate: true, - ondestroy: false, + onDestroy: false, onstate: false, - onupdate: false + afterRender: false }); } }; \ No newline at end of file diff --git a/test/stats/samples/hooks/input.html b/test/stats/samples/hooks/input.html index 885f4d3962..dd5e4ce63b 100644 --- a/test/stats/samples/hooks/input.html +++ b/test/stats/samples/hooks/input.html @@ -1,7 +1,7 @@ \ No newline at end of file diff --git a/test/validator/samples/oncreate-arrow-no-this/input.html b/test/validator/samples/oncreate-arrow-no-this/input.html index 218f00232f..21084bb4a6 100644 --- a/test/validator/samples/oncreate-arrow-no-this/input.html +++ b/test/validator/samples/oncreate-arrow-no-this/input.html @@ -1,5 +1,5 @@ diff --git a/test/validator/samples/ondestroy-arrow-no-this/input.html b/test/validator/samples/ondestroy-arrow-no-this/input.html index addd9cc4db..ea9c367ee5 100644 --- a/test/validator/samples/ondestroy-arrow-no-this/input.html +++ b/test/validator/samples/ondestroy-arrow-no-this/input.html @@ -1,5 +1,5 @@ diff --git a/test/validator/samples/ondestroy-arrow-this/errors.json b/test/validator/samples/ondestroy-arrow-this/errors.json index c2f7f7ef4b..cb9eb915fd 100644 --- a/test/validator/samples/ondestroy-arrow-this/errors.json +++ b/test/validator/samples/ondestroy-arrow-this/errors.json @@ -1,6 +1,6 @@ [{ - "code": "invalid-ondestroy-property", - "message": "'ondestroy' should be a function expression, not an arrow function expression", + "code": "invalid-onDestroy-property", + "message": "'onDestroy' should be a function expression, not an arrow function expression", "pos": 29, "start": { "line": 3, diff --git a/test/validator/samples/ondestroy-arrow-this/input.html b/test/validator/samples/ondestroy-arrow-this/input.html index 2f5df93962..6529efe575 100644 --- a/test/validator/samples/ondestroy-arrow-this/input.html +++ b/test/validator/samples/ondestroy-arrow-this/input.html @@ -1,6 +1,6 @@ diff --git a/test/validator/samples/onupdate-arrow-no-this/input.html b/test/validator/samples/onupdate-arrow-no-this/input.html index f0bc35c9f0..c1ea0b16ba 100644 --- a/test/validator/samples/onupdate-arrow-no-this/input.html +++ b/test/validator/samples/onupdate-arrow-no-this/input.html @@ -1,5 +1,5 @@ diff --git a/test/validator/samples/onupdate-arrow-this/errors.json b/test/validator/samples/onupdate-arrow-this/errors.json index 8605fc46b8..aaf4b057a2 100644 --- a/test/validator/samples/onupdate-arrow-this/errors.json +++ b/test/validator/samples/onupdate-arrow-this/errors.json @@ -1,6 +1,6 @@ [{ - "code": "invalid-onupdate-property", - "message": "'onupdate' should be a function expression, not an arrow function expression", + "code": "invalid-afterRender-property", + "message": "'afterRender' should be a function expression, not an arrow function expression", "pos": 29, "start": { "line": 3, diff --git a/test/validator/samples/onupdate-arrow-this/input.html b/test/validator/samples/onupdate-arrow-this/input.html index 3f4dcd897d..092e9bb9b2 100644 --- a/test/validator/samples/onupdate-arrow-this/input.html +++ b/test/validator/samples/onupdate-arrow-this/input.html @@ -1,6 +1,6 @@