From bd002f94bcf76d008d6577017585695b50afb272 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 16 Sep 2017 15:09:38 -0400 Subject: [PATCH 1/3] extract some shared init logic --- src/generators/dom/index.ts | 11 +----- src/shared/index.js | 23 +++++++++--- .../expected-bundle.js | 36 ++++++++++--------- .../expected.js | 15 ++------ .../computed-collapsed-if/expected-bundle.js | 36 ++++++++++--------- .../samples/computed-collapsed-if/expected.js | 15 ++------ .../css-media-query/expected-bundle.js | 36 ++++++++++--------- test/js/samples/css-media-query/expected.js | 15 ++------ .../expected-bundle.js | 36 ++++++++++--------- .../css-shadow-dom-keyframes/expected.js | 15 ++------ .../expected-bundle.js | 36 ++++++++++--------- .../each-block-changed-check/expected.js | 15 ++------ .../event-handlers-custom/expected-bundle.js | 36 ++++++++++--------- .../samples/event-handlers-custom/expected.js | 15 ++------ .../if-block-no-update/expected-bundle.js | 36 ++++++++++--------- .../js/samples/if-block-no-update/expected.js | 15 ++------ .../if-block-simple/expected-bundle.js | 36 ++++++++++--------- test/js/samples/if-block-simple/expected.js | 15 ++------ .../expected-bundle.js | 36 ++++++++++--------- .../expected.js | 15 ++------ .../expected-bundle.js | 36 ++++++++++--------- .../inline-style-optimized-url/expected.js | 15 ++------ .../inline-style-optimized/expected-bundle.js | 36 ++++++++++--------- .../inline-style-optimized/expected.js | 15 ++------ .../expected-bundle.js | 36 ++++++++++--------- .../inline-style-unoptimized/expected.js | 15 ++------ .../expected-bundle.js | 36 ++++++++++--------- .../input-without-blowback-guard/expected.js | 15 ++------ .../legacy-input-type/expected-bundle.js | 36 ++++++++++--------- test/js/samples/legacy-input-type/expected.js | 15 ++------ .../legacy-quote-class/expected-bundle.js | 36 ++++++++++--------- .../js/samples/legacy-quote-class/expected.js | 15 ++------ .../samples/media-bindings/expected-bundle.js | 36 ++++++++++--------- test/js/samples/media-bindings/expected.js | 15 ++------ .../non-imported-component/expected-bundle.js | 36 ++++++++++--------- .../non-imported-component/expected.js | 15 ++------ .../expected-bundle.js | 35 ++++++++++-------- .../onrender-onteardown-rewritten/expected.js | 14 ++------ .../samples/setup-method/expected-bundle.js | 36 ++++++++++--------- test/js/samples/setup-method/expected.js | 15 ++------ .../expected-bundle.js | 36 ++++++++++--------- .../use-elements-as-anchors/expected.js | 15 ++------ 42 files changed, 460 insertions(+), 592 deletions(-) diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts index 8d82fef182..6eaf256353 100644 --- a/src/generators/dom/index.ts +++ b/src/generators/dom/index.ts @@ -153,7 +153,7 @@ export default function dom( ${options.dev && `this._debugName = '${debugName}';`} ${options.dev && !generator.customElement && `if (!options || (!options.target && !options._root)) throw new Error("'target' is a required option");`} - this.options = options; + @init(this, options); ${generator.usesRefs && `this.refs = {};`} this._state = ${templateProperties.data ? `@assign(@template.data(), options.data)` @@ -168,17 +168,8 @@ export default function dom( ${generator.bindingGroups.length && `this._bindingGroups = [${Array(generator.bindingGroups.length).fill('[]').join(', ')}];`} - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); ${templateProperties.ondestroy && `this._handlers.destroy = [@template.ondestroy]`} - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; ${generator.slots.size && `this._slotted = options.slots || {};`} ${generator.customElement ? diff --git a/src/shared/index.js b/src/shared/index.js index 34d85897df..001babe349 100644 --- a/src/shared/index.js +++ b/src/shared/index.js @@ -46,10 +46,6 @@ export function dispatchObservers(component, group, changed, newState, oldState) } } -export function get(key) { - return key ? this._state[key] : this._state; -} - export function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -60,6 +56,25 @@ export function fire(eventName, data) { } } +export function get(key) { + return key ? this._state[key] : this._state; +} + +export function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + export function observe(key, callback, options) { var group = options && options.defer ? this._observers.post diff --git a/test/js/samples/collapses-text-around-comments/expected-bundle.js b/test/js/samples/collapses-text-around-comments/expected-bundle.js index 5e61b5cb39..c421eadb7d 100644 --- a/test/js/samples/collapses-text-around-comments/expected-bundle.js +++ b/test/js/samples/collapses-text-around-comments/expected-bundle.js @@ -72,10 +72,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -86,6 +82,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -228,20 +243,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = assign(template.data(), options.data); - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - if (!document.getElementById("svelte-3590263702-style")) add_css(); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/collapses-text-around-comments/expected.js b/test/js/samples/collapses-text-around-comments/expected.js index dd6689737e..2ad2187e95 100644 --- a/test/js/samples/collapses-text-around-comments/expected.js +++ b/test/js/samples/collapses-text-around-comments/expected.js @@ -1,4 +1,4 @@ -import { appendNode, assign, createElement, createText, detachNode, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; +import { appendNode, assign, createElement, createText, detachNode, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; var template = (function() { return { @@ -53,20 +53,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = assign(template.data(), options.data); - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - if (!document.getElementById("svelte-3590263702-style")) add_css(); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/computed-collapsed-if/expected-bundle.js b/test/js/samples/computed-collapsed-if/expected-bundle.js index 5e7b1d99c7..7296201e36 100644 --- a/test/js/samples/computed-collapsed-if/expected-bundle.js +++ b/test/js/samples/computed-collapsed-if/expected-bundle.js @@ -48,10 +48,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -62,6 +58,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -176,21 +191,10 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; this._recompute({}, this._state, {}, true); - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/computed-collapsed-if/expected.js b/test/js/samples/computed-collapsed-if/expected.js index 87804092f2..48e3445dd8 100644 --- a/test/js/samples/computed-collapsed-if/expected.js +++ b/test/js/samples/computed-collapsed-if/expected.js @@ -1,4 +1,4 @@ -import { assign, differs, noop, proto } from "svelte/shared.js"; +import { assign, differs, init, noop, proto } from "svelte/shared.js"; var template = (function() { return { @@ -25,21 +25,10 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; this._recompute({}, this._state, {}, true); - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/css-media-query/expected-bundle.js b/test/js/samples/css-media-query/expected-bundle.js index bba05e07aa..30f8a023a9 100644 --- a/test/js/samples/css-media-query/expected-bundle.js +++ b/test/js/samples/css-media-query/expected-bundle.js @@ -68,10 +68,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -82,6 +78,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -210,20 +225,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - if (!document.getElementById("svelte-2363328337-style")) add_css(); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/css-media-query/expected.js b/test/js/samples/css-media-query/expected.js index 8a70516367..4dcb8f9fb3 100644 --- a/test/js/samples/css-media-query/expected.js +++ b/test/js/samples/css-media-query/expected.js @@ -1,4 +1,4 @@ -import { appendNode, assign, createElement, detachNode, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; +import { appendNode, assign, createElement, detachNode, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; function encapsulateStyles(node) { setAttribute(node, "svelte-2363328337", ""); @@ -39,20 +39,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - if (!document.getElementById("svelte-2363328337-style")) add_css(); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js b/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js index 8e3fa4e47f..d19b44002d 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js @@ -68,10 +68,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -82,6 +78,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -198,20 +213,9 @@ function create_main_fragment(state, component) { class SvelteComponent extends HTMLElement { constructor(options = {}) { super(); - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this.attachShadow({ mode: 'open' }); this.shadowRoot.innerHTML = ``; diff --git a/test/js/samples/css-shadow-dom-keyframes/expected.js b/test/js/samples/css-shadow-dom-keyframes/expected.js index 87cf2940bd..2814d24901 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected.js @@ -1,4 +1,4 @@ -import { appendNode, assign, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +import { appendNode, assign, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var div, text; @@ -27,20 +27,9 @@ function create_main_fragment(state, component) { class SvelteComponent extends HTMLElement { constructor(options = {}) { super(); - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this.attachShadow({ mode: 'open' }); this.shadowRoot.innerHTML = ``; diff --git a/test/js/samples/each-block-changed-check/expected-bundle.js b/test/js/samples/each-block-changed-check/expected-bundle.js index 28bd3c608d..97f6371f23 100644 --- a/test/js/samples/each-block-changed-check/expected-bundle.js +++ b/test/js/samples/each-block-changed-check/expected-bundle.js @@ -81,10 +81,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -95,6 +91,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -322,20 +337,9 @@ function create_each_block(state, each_block_value, comment, i, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js index 5fec542b69..8931d83aab 100644 --- a/test/js/samples/each-block-changed-check/expected.js +++ b/test/js/samples/each-block-changed-check/expected.js @@ -1,4 +1,4 @@ -import { appendNode, assign, createElement, createText, destroyEach, detachAfter, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +import { appendNode, assign, createElement, createText, destroyEach, detachAfter, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var text, p, text_1; @@ -138,20 +138,9 @@ function create_each_block(state, each_block_value, comment, i, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/event-handlers-custom/expected-bundle.js b/test/js/samples/event-handlers-custom/expected-bundle.js index 9a683c9dab..5f117e9ce9 100644 --- a/test/js/samples/event-handlers-custom/expected-bundle.js +++ b/test/js/samples/event-handlers-custom/expected-bundle.js @@ -68,10 +68,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -82,6 +78,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -221,20 +236,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/event-handlers-custom/expected.js b/test/js/samples/event-handlers-custom/expected.js index e123de9c98..b08c6335f8 100644 --- a/test/js/samples/event-handlers-custom/expected.js +++ b/test/js/samples/event-handlers-custom/expected.js @@ -1,4 +1,4 @@ -import { appendNode, assign, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +import { appendNode, assign, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; var template = (function() { return { @@ -50,20 +50,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/if-block-no-update/expected-bundle.js b/test/js/samples/if-block-no-update/expected-bundle.js index 00418f43cc..dcc893079b 100644 --- a/test/js/samples/if-block-no-update/expected-bundle.js +++ b/test/js/samples/if-block-no-update/expected-bundle.js @@ -72,10 +72,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -86,6 +82,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -263,20 +278,9 @@ function select_block_type(state) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/if-block-no-update/expected.js b/test/js/samples/if-block-no-update/expected.js index 619465c331..4db0d11949 100644 --- a/test/js/samples/if-block-no-update/expected.js +++ b/test/js/samples/if-block-no-update/expected.js @@ -1,4 +1,4 @@ -import { appendNode, assign, createComment, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +import { appendNode, assign, createComment, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var if_block_anchor; @@ -88,20 +88,9 @@ function select_block_type(state) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/if-block-simple/expected-bundle.js b/test/js/samples/if-block-simple/expected-bundle.js index 6798ecce54..6612ead376 100644 --- a/test/js/samples/if-block-simple/expected-bundle.js +++ b/test/js/samples/if-block-simple/expected-bundle.js @@ -72,10 +72,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -86,6 +82,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -239,20 +254,9 @@ function create_if_block(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/if-block-simple/expected.js b/test/js/samples/if-block-simple/expected.js index f003447f3b..e229b23ee8 100644 --- a/test/js/samples/if-block-simple/expected.js +++ b/test/js/samples/if-block-simple/expected.js @@ -1,4 +1,4 @@ -import { appendNode, assign, createComment, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +import { appendNode, assign, createComment, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var if_block_anchor; @@ -64,20 +64,9 @@ function create_if_block(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/inline-style-optimized-multiple/expected-bundle.js b/test/js/samples/inline-style-optimized-multiple/expected-bundle.js index 019bf5e86b..190e86eb44 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-multiple/expected-bundle.js @@ -64,10 +64,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -78,6 +74,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -204,20 +219,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/inline-style-optimized-multiple/expected.js b/test/js/samples/inline-style-optimized-multiple/expected.js index 540cee99bc..2ae613643e 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected.js +++ b/test/js/samples/inline-style-optimized-multiple/expected.js @@ -1,4 +1,4 @@ -import { assign, createElement, detachNode, insertNode, noop, proto, setStyle } from "svelte/shared.js"; +import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; function create_main_fragment(state, component) { var div; @@ -37,20 +37,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/inline-style-optimized-url/expected-bundle.js b/test/js/samples/inline-style-optimized-url/expected-bundle.js index 05aa4df9d7..15076819cb 100644 --- a/test/js/samples/inline-style-optimized-url/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-url/expected-bundle.js @@ -64,10 +64,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -78,6 +74,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -199,20 +214,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/inline-style-optimized-url/expected.js b/test/js/samples/inline-style-optimized-url/expected.js index d5d415aafd..de8e6ffec2 100644 --- a/test/js/samples/inline-style-optimized-url/expected.js +++ b/test/js/samples/inline-style-optimized-url/expected.js @@ -1,4 +1,4 @@ -import { assign, createElement, detachNode, insertNode, noop, proto, setStyle } from "svelte/shared.js"; +import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; function create_main_fragment(state, component) { var div; @@ -32,20 +32,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/inline-style-optimized/expected-bundle.js b/test/js/samples/inline-style-optimized/expected-bundle.js index 91db41380b..8640267814 100644 --- a/test/js/samples/inline-style-optimized/expected-bundle.js +++ b/test/js/samples/inline-style-optimized/expected-bundle.js @@ -64,10 +64,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -78,6 +74,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -199,20 +214,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/inline-style-optimized/expected.js b/test/js/samples/inline-style-optimized/expected.js index e4816ffbfb..54b6de1646 100644 --- a/test/js/samples/inline-style-optimized/expected.js +++ b/test/js/samples/inline-style-optimized/expected.js @@ -1,4 +1,4 @@ -import { assign, createElement, detachNode, insertNode, noop, proto, setStyle } from "svelte/shared.js"; +import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; function create_main_fragment(state, component) { var div; @@ -32,20 +32,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/inline-style-unoptimized/expected-bundle.js b/test/js/samples/inline-style-unoptimized/expected-bundle.js index cfe849e3f9..f12a26da07 100644 --- a/test/js/samples/inline-style-unoptimized/expected-bundle.js +++ b/test/js/samples/inline-style-unoptimized/expected-bundle.js @@ -64,10 +64,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -78,6 +74,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -210,20 +225,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/inline-style-unoptimized/expected.js b/test/js/samples/inline-style-unoptimized/expected.js index 209cc90df6..63c32e26cf 100644 --- a/test/js/samples/inline-style-unoptimized/expected.js +++ b/test/js/samples/inline-style-unoptimized/expected.js @@ -1,4 +1,4 @@ -import { assign, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +import { assign, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var div, text, div_1, div_1_style_value; @@ -43,20 +43,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/input-without-blowback-guard/expected-bundle.js b/test/js/samples/input-without-blowback-guard/expected-bundle.js index c5cfd84bec..0a9b7dc47d 100644 --- a/test/js/samples/input-without-blowback-guard/expected-bundle.js +++ b/test/js/samples/input-without-blowback-guard/expected-bundle.js @@ -68,10 +68,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -82,6 +78,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -210,20 +225,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/input-without-blowback-guard/expected.js b/test/js/samples/input-without-blowback-guard/expected.js index b459bdb7c8..4b987311f2 100644 --- a/test/js/samples/input-without-blowback-guard/expected.js +++ b/test/js/samples/input-without-blowback-guard/expected.js @@ -1,4 +1,4 @@ -import { addListener, assign, createElement, detachNode, insertNode, proto, removeListener } from "svelte/shared.js"; +import { addListener, assign, createElement, detachNode, init, insertNode, proto, removeListener } from "svelte/shared.js"; function create_main_fragment(state, component) { var input; @@ -39,20 +39,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/legacy-input-type/expected-bundle.js b/test/js/samples/legacy-input-type/expected-bundle.js index f34e19450e..338b70b5d9 100644 --- a/test/js/samples/legacy-input-type/expected-bundle.js +++ b/test/js/samples/legacy-input-type/expected-bundle.js @@ -66,10 +66,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -80,6 +76,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -197,20 +212,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/legacy-input-type/expected.js b/test/js/samples/legacy-input-type/expected.js index 9f585862e1..3e8b6714e0 100644 --- a/test/js/samples/legacy-input-type/expected.js +++ b/test/js/samples/legacy-input-type/expected.js @@ -1,4 +1,4 @@ -import { assign, createElement, detachNode, insertNode, noop, proto, setInputType } from "svelte/shared.js"; +import { assign, createElement, detachNode, init, insertNode, noop, proto, setInputType } from "svelte/shared.js"; function create_main_fragment(state, component) { var input; @@ -28,20 +28,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/legacy-quote-class/expected-bundle.js b/test/js/samples/legacy-quote-class/expected-bundle.js index bf4bf86be9..8c10d0af06 100644 --- a/test/js/samples/legacy-quote-class/expected-bundle.js +++ b/test/js/samples/legacy-quote-class/expected-bundle.js @@ -83,10 +83,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -97,6 +93,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -222,20 +237,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/legacy-quote-class/expected.js b/test/js/samples/legacy-quote-class/expected.js index 7eec7950fd..1a4de07a5b 100644 --- a/test/js/samples/legacy-quote-class/expected.js +++ b/test/js/samples/legacy-quote-class/expected.js @@ -1,4 +1,4 @@ -import { assign, children, claimElement, createElement, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +import { assign, children, claimElement, createElement, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var div; @@ -36,20 +36,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/media-bindings/expected-bundle.js b/test/js/samples/media-bindings/expected-bundle.js index 8dca649745..1f78b237cc 100644 --- a/test/js/samples/media-bindings/expected-bundle.js +++ b/test/js/samples/media-bindings/expected-bundle.js @@ -76,10 +76,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -90,6 +86,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -286,20 +301,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - if (!options._root) { this._oncreate = []; this._beforecreate = []; diff --git a/test/js/samples/media-bindings/expected.js b/test/js/samples/media-bindings/expected.js index 738de4f815..b19656cf34 100644 --- a/test/js/samples/media-bindings/expected.js +++ b/test/js/samples/media-bindings/expected.js @@ -1,4 +1,4 @@ -import { addListener, assign, callAll, createElement, detachNode, insertNode, proto, removeListener, timeRangesToArray } from "svelte/shared.js"; +import { addListener, assign, callAll, createElement, detachNode, init, insertNode, proto, removeListener, timeRangesToArray } from "svelte/shared.js"; function create_main_fragment(state, component) { var audio, audio_updating = false, audio_animationframe, audio_paused_value = true; @@ -107,20 +107,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - if (!options._root) { this._oncreate = []; this._beforecreate = []; diff --git a/test/js/samples/non-imported-component/expected-bundle.js b/test/js/samples/non-imported-component/expected-bundle.js index 6d5ea4bba3..261f63dcbd 100644 --- a/test/js/samples/non-imported-component/expected-bundle.js +++ b/test/js/samples/non-imported-component/expected-bundle.js @@ -62,10 +62,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -76,6 +72,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -213,20 +228,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - if (!options._root) { this._oncreate = []; this._beforecreate = []; diff --git a/test/js/samples/non-imported-component/expected.js b/test/js/samples/non-imported-component/expected.js index de96d252be..ef6a106de7 100644 --- a/test/js/samples/non-imported-component/expected.js +++ b/test/js/samples/non-imported-component/expected.js @@ -1,6 +1,6 @@ import Imported from 'Imported.html'; -import { assign, callAll, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +import { assign, callAll, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; var template = (function() { return { @@ -50,20 +50,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - if (!options._root) { this._oncreate = []; this._beforecreate = []; diff --git a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js index 272f822a9e..95e0119a24 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js @@ -48,10 +48,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -62,6 +58,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -175,21 +190,11 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); this._handlers.destroy = [template.ondestroy]; - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - var oncreate = template.oncreate.bind(this); if (!options._root) { diff --git a/test/js/samples/onrender-onteardown-rewritten/expected.js b/test/js/samples/onrender-onteardown-rewritten/expected.js index 32a116b3a1..6e2df0f9be 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected.js @@ -1,4 +1,4 @@ -import { assign, callAll, noop, proto } from "svelte/shared.js"; +import { assign, callAll, init, noop, proto } from "svelte/shared.js"; var template = (function() { return { @@ -24,21 +24,11 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); this._handlers.destroy = [template.ondestroy] - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - var oncreate = template.oncreate.bind(this); if (!options._root) { diff --git a/test/js/samples/setup-method/expected-bundle.js b/test/js/samples/setup-method/expected-bundle.js index 6967036e49..0f2fb2685c 100644 --- a/test/js/samples/setup-method/expected-bundle.js +++ b/test/js/samples/setup-method/expected-bundle.js @@ -48,10 +48,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -62,6 +58,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -186,20 +201,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/setup-method/expected.js b/test/js/samples/setup-method/expected.js index 50d2ec47c5..90d98f0947 100644 --- a/test/js/samples/setup-method/expected.js +++ b/test/js/samples/setup-method/expected.js @@ -1,4 +1,4 @@ -import { assign, noop, proto } from "svelte/shared.js"; +import { assign, init, noop, proto } from "svelte/shared.js"; var template = (function() { return { @@ -35,20 +35,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/use-elements-as-anchors/expected-bundle.js b/test/js/samples/use-elements-as-anchors/expected-bundle.js index dc41a1501f..d3ae8b9976 100644 --- a/test/js/samples/use-elements-as-anchors/expected-bundle.js +++ b/test/js/samples/use-elements-as-anchors/expected-bundle.js @@ -72,10 +72,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -86,6 +82,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -423,20 +438,9 @@ function create_if_block_4(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/use-elements-as-anchors/expected.js b/test/js/samples/use-elements-as-anchors/expected.js index d520ee49e6..156f83674a 100644 --- a/test/js/samples/use-elements-as-anchors/expected.js +++ b/test/js/samples/use-elements-as-anchors/expected.js @@ -1,4 +1,4 @@ -import { appendNode, assign, createComment, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +import { appendNode, assign, createComment, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var div, text, p, text_1, text_2, text_3, text_4, p_1, text_5, text_6, text_8, if_block_4_anchor; @@ -248,20 +248,9 @@ function create_if_block_4(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { From ef3cf343674088b5686b8a50a72cfa0b4dba8c1c Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 16 Sep 2017 15:15:23 -0400 Subject: [PATCH 2/3] tighten up a bit more --- src/generators/dom/visitors/EachBlock.ts | 2 +- src/shared/index.js | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/generators/dom/visitors/EachBlock.ts b/src/generators/dom/visitors/EachBlock.ts index e0d941511e..03c0918ce0 100644 --- a/src/generators/dom/visitors/EachBlock.ts +++ b/src/generators/dom/visitors/EachBlock.ts @@ -160,7 +160,7 @@ function keyed( const last = block.getUniqueName(`${each_block}_last`); const expected = block.getUniqueName(`${each_block}_expected`); - block.addVariable(lookup, `Object.create(null)`); + block.addVariable(lookup, `@blankObject()`); block.addVariable(head); block.addVariable(last); diff --git a/src/shared/index.js b/src/shared/index.js index 001babe349..dcc2895831 100644 --- a/src/shared/index.js +++ b/src/shared/index.js @@ -4,6 +4,10 @@ export * from './dom.js'; export * from './transitions.js'; export * from './utils.js'; +export function blankObject() { + return Object.create(null); +} + export function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -63,13 +67,8 @@ export function get(key) { export function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; From 0b71a937798cf00f77d8fffbb9bdb55fa968b0b4 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 16 Sep 2017 15:20:43 -0400 Subject: [PATCH 3/3] update tests --- .../expected-bundle.js | 13 ++++++------- .../computed-collapsed-if/expected-bundle.js | 13 ++++++------- test/js/samples/css-media-query/expected-bundle.js | 13 ++++++------- .../css-shadow-dom-keyframes/expected-bundle.js | 13 ++++++------- .../each-block-changed-check/expected-bundle.js | 13 ++++++------- .../event-handlers-custom/expected-bundle.js | 13 ++++++------- .../samples/if-block-no-update/expected-bundle.js | 13 ++++++------- test/js/samples/if-block-simple/expected-bundle.js | 13 ++++++------- .../expected-bundle.js | 13 ++++++------- .../inline-style-optimized-url/expected-bundle.js | 13 ++++++------- .../inline-style-optimized/expected-bundle.js | 13 ++++++------- .../inline-style-unoptimized/expected-bundle.js | 13 ++++++------- .../input-without-blowback-guard/expected-bundle.js | 13 ++++++------- .../js/samples/legacy-input-type/expected-bundle.js | 13 ++++++------- .../samples/legacy-quote-class/expected-bundle.js | 13 ++++++------- test/js/samples/media-bindings/expected-bundle.js | 13 ++++++------- .../non-imported-component/expected-bundle.js | 13 ++++++------- .../expected-bundle.js | 13 ++++++------- test/js/samples/setup-method/expected-bundle.js | 13 ++++++------- .../use-elements-as-anchors/expected-bundle.js | 13 ++++++------- 20 files changed, 120 insertions(+), 140 deletions(-) diff --git a/test/js/samples/collapses-text-around-comments/expected-bundle.js b/test/js/samples/collapses-text-around-comments/expected-bundle.js index c421eadb7d..548fabf94b 100644 --- a/test/js/samples/collapses-text-around-comments/expected-bundle.js +++ b/test/js/samples/collapses-text-around-comments/expected-bundle.js @@ -37,6 +37,10 @@ function setAttribute(node, attribute, value) { node.setAttribute(attribute, value); } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -89,13 +93,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; diff --git a/test/js/samples/computed-collapsed-if/expected-bundle.js b/test/js/samples/computed-collapsed-if/expected-bundle.js index 7296201e36..c511b16af4 100644 --- a/test/js/samples/computed-collapsed-if/expected-bundle.js +++ b/test/js/samples/computed-collapsed-if/expected-bundle.js @@ -13,6 +13,10 @@ function assign(target) { return target; } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -65,13 +69,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; diff --git a/test/js/samples/css-media-query/expected-bundle.js b/test/js/samples/css-media-query/expected-bundle.js index 30f8a023a9..0b5f496608 100644 --- a/test/js/samples/css-media-query/expected-bundle.js +++ b/test/js/samples/css-media-query/expected-bundle.js @@ -33,6 +33,10 @@ function setAttribute(node, attribute, value) { node.setAttribute(attribute, value); } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -85,13 +89,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; diff --git a/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js b/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js index d19b44002d..5659f8d71c 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js @@ -33,6 +33,10 @@ function createText(data) { return document.createTextNode(data); } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -85,13 +89,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; diff --git a/test/js/samples/each-block-changed-check/expected-bundle.js b/test/js/samples/each-block-changed-check/expected-bundle.js index 97f6371f23..593cb2c76a 100644 --- a/test/js/samples/each-block-changed-check/expected-bundle.js +++ b/test/js/samples/each-block-changed-check/expected-bundle.js @@ -46,6 +46,10 @@ function createText(data) { return document.createTextNode(data); } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -98,13 +102,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; diff --git a/test/js/samples/event-handlers-custom/expected-bundle.js b/test/js/samples/event-handlers-custom/expected-bundle.js index 5f117e9ce9..da43b1c1f6 100644 --- a/test/js/samples/event-handlers-custom/expected-bundle.js +++ b/test/js/samples/event-handlers-custom/expected-bundle.js @@ -33,6 +33,10 @@ function createText(data) { return document.createTextNode(data); } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -85,13 +89,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; diff --git a/test/js/samples/if-block-no-update/expected-bundle.js b/test/js/samples/if-block-no-update/expected-bundle.js index dcc893079b..7e04a6295b 100644 --- a/test/js/samples/if-block-no-update/expected-bundle.js +++ b/test/js/samples/if-block-no-update/expected-bundle.js @@ -37,6 +37,10 @@ function createComment() { return document.createComment(''); } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -89,13 +93,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; diff --git a/test/js/samples/if-block-simple/expected-bundle.js b/test/js/samples/if-block-simple/expected-bundle.js index 6612ead376..4c9e853523 100644 --- a/test/js/samples/if-block-simple/expected-bundle.js +++ b/test/js/samples/if-block-simple/expected-bundle.js @@ -37,6 +37,10 @@ function createComment() { return document.createComment(''); } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -89,13 +93,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; diff --git a/test/js/samples/inline-style-optimized-multiple/expected-bundle.js b/test/js/samples/inline-style-optimized-multiple/expected-bundle.js index 190e86eb44..8579875048 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-multiple/expected-bundle.js @@ -29,6 +29,10 @@ function setStyle(node, key, value) { node.style.setProperty(key, value); } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -81,13 +85,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; diff --git a/test/js/samples/inline-style-optimized-url/expected-bundle.js b/test/js/samples/inline-style-optimized-url/expected-bundle.js index 15076819cb..9246e5da3f 100644 --- a/test/js/samples/inline-style-optimized-url/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-url/expected-bundle.js @@ -29,6 +29,10 @@ function setStyle(node, key, value) { node.style.setProperty(key, value); } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -81,13 +85,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; diff --git a/test/js/samples/inline-style-optimized/expected-bundle.js b/test/js/samples/inline-style-optimized/expected-bundle.js index 8640267814..bf1042f922 100644 --- a/test/js/samples/inline-style-optimized/expected-bundle.js +++ b/test/js/samples/inline-style-optimized/expected-bundle.js @@ -29,6 +29,10 @@ function setStyle(node, key, value) { node.style.setProperty(key, value); } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -81,13 +85,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; diff --git a/test/js/samples/inline-style-unoptimized/expected-bundle.js b/test/js/samples/inline-style-unoptimized/expected-bundle.js index f12a26da07..578be1689d 100644 --- a/test/js/samples/inline-style-unoptimized/expected-bundle.js +++ b/test/js/samples/inline-style-unoptimized/expected-bundle.js @@ -29,6 +29,10 @@ function createText(data) { return document.createTextNode(data); } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -81,13 +85,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; diff --git a/test/js/samples/input-without-blowback-guard/expected-bundle.js b/test/js/samples/input-without-blowback-guard/expected-bundle.js index 0a9b7dc47d..c9222e4511 100644 --- a/test/js/samples/input-without-blowback-guard/expected-bundle.js +++ b/test/js/samples/input-without-blowback-guard/expected-bundle.js @@ -33,6 +33,10 @@ function removeListener(node, event, handler) { node.removeEventListener(event, handler, false); } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -85,13 +89,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; diff --git a/test/js/samples/legacy-input-type/expected-bundle.js b/test/js/samples/legacy-input-type/expected-bundle.js index 338b70b5d9..55496415c4 100644 --- a/test/js/samples/legacy-input-type/expected-bundle.js +++ b/test/js/samples/legacy-input-type/expected-bundle.js @@ -31,6 +31,10 @@ function setInputType(input, type) { } catch (e) {} } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -83,13 +87,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; diff --git a/test/js/samples/legacy-quote-class/expected-bundle.js b/test/js/samples/legacy-quote-class/expected-bundle.js index 8c10d0af06..41d45271af 100644 --- a/test/js/samples/legacy-quote-class/expected-bundle.js +++ b/test/js/samples/legacy-quote-class/expected-bundle.js @@ -48,6 +48,10 @@ function claimElement (nodes, name, attributes, svg) { return svg ? createSvgElement(name) : createElement(name); } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -100,13 +104,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; diff --git a/test/js/samples/media-bindings/expected-bundle.js b/test/js/samples/media-bindings/expected-bundle.js index 1f78b237cc..39f2e2c682 100644 --- a/test/js/samples/media-bindings/expected-bundle.js +++ b/test/js/samples/media-bindings/expected-bundle.js @@ -41,6 +41,10 @@ function timeRangesToArray(ranges) { return array; } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -93,13 +97,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; diff --git a/test/js/samples/non-imported-component/expected-bundle.js b/test/js/samples/non-imported-component/expected-bundle.js index 261f63dcbd..33172b6954 100644 --- a/test/js/samples/non-imported-component/expected-bundle.js +++ b/test/js/samples/non-imported-component/expected-bundle.js @@ -27,6 +27,10 @@ function createText(data) { return document.createTextNode(data); } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -79,13 +83,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; diff --git a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js index 95e0119a24..76c83b2097 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js @@ -13,6 +13,10 @@ function assign(target) { return target; } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -65,13 +69,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; diff --git a/test/js/samples/setup-method/expected-bundle.js b/test/js/samples/setup-method/expected-bundle.js index 0f2fb2685c..c936fc549e 100644 --- a/test/js/samples/setup-method/expected-bundle.js +++ b/test/js/samples/setup-method/expected-bundle.js @@ -13,6 +13,10 @@ function assign(target) { return target; } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -65,13 +69,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; diff --git a/test/js/samples/use-elements-as-anchors/expected-bundle.js b/test/js/samples/use-elements-as-anchors/expected-bundle.js index d3ae8b9976..362c8a45fb 100644 --- a/test/js/samples/use-elements-as-anchors/expected-bundle.js +++ b/test/js/samples/use-elements-as-anchors/expected-bundle.js @@ -37,6 +37,10 @@ function createComment() { return document.createComment(''); } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -89,13 +93,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind;