diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts index 5a1a678e63..dc62ed136f 100644 --- a/src/generators/dom/index.ts +++ b/src/generators/dom/index.ts @@ -133,17 +133,6 @@ export default function dom( ? 'svelte/shared.js' : options.shared || ''; - let prototypeBase = `${name}.prototype`; - - const proto = sharedPath - ? `@Component.prototype` - : deindent` - { - ${['destroy', 'get', 'fire', 'on', 'set', '_set', '_mount', '_unmount', '_differs'] - .map(n => `${n}: @${n}`) - .join(',\n')} - }`; - const debugName = `<${generator.customElement ? generator.tag : name}>`; // generate initial state object @@ -172,8 +161,6 @@ export default function dom( const constructorBody = deindent` ${options.dev && `this._debugName = '${debugName}';`} - ${options.dev && !generator.customElement && - `if (!options || (!options.target && !options.root)) throw new Error("'target' is a required option");`} ${templateProperties.store && `this.store = %store();`} ${generator.usesRefs && `this.refs = {};`} this._state = ${initialState.reduce((state, piece) => `@assign(${state}, ${piece})`)}; @@ -280,6 +267,8 @@ export default function dom( class ${name} extends HTMLElement { constructor(options = {}) { super(); + this._handlers = {}; + this._init.call(this, options); ${constructorBody} } @@ -319,8 +308,16 @@ export default function dom( `} } - customElements.define("${generator.tag}", ${name}); - @assign(@assign(${prototypeBase}, ${proto}), { + Object.getOwnPropertyNames(${generator.options.dev ? `Object.getPrototypeOf(@Component.prototype)` : `@Component.prototype`}).forEach(name => { + ${name}.prototype[name] = @Component.prototype[name]; + }); + + @assign(${name}.prototype, { + fire: @Base.prototype.fire, + get: @Base.prototype.get, + on: @Base.prototype.on, + _differs: @Base.prototype._differs, + _mount(target, anchor) { target.insertBefore(this, anchor); }, @@ -329,6 +326,8 @@ export default function dom( this.parentNode.removeChild(this); } }); + + customElements.define("${generator.tag}", ${name}); `); } else { // TODO put methods in class body diff --git a/src/shared/index.js b/src/shared/index.js index 21cb0aadfb..020a8f399c 100644 --- a/src/shared/index.js +++ b/src/shared/index.js @@ -54,11 +54,7 @@ export class Base { export class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -81,6 +77,14 @@ export class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {}; @@ -115,6 +119,14 @@ export class Component extends Base { } export class ComponentDev extends Component { + constructor(options) { + if (!options || (!options.target && !options.root)) { + throw new Error(`'target' is a required option`); + } + + super(options); + } + destroy(detach) { super.destroy(detach); this.destroy = () => { diff --git a/test/custom-elements/index.js b/test/custom-elements/index.js index 7675e0c188..52d4b7da59 100644 --- a/test/custom-elements/index.js +++ b/test/custom-elements/index.js @@ -23,6 +23,10 @@ describe('custom-elements', function() { console[type](...args); }); + nightmare.on('page', (type, message, stack) => { + console.error(stack); + }); + let svelte; let server; let bundle; diff --git a/test/js/samples/action/expected-bundle.js b/test/js/samples/action/expected-bundle.js index 9bfb8f37f6..6b0da6f682 100644 --- a/test/js/samples/action/expected-bundle.js +++ b/test/js/samples/action/expected-bundle.js @@ -65,11 +65,7 @@ class Base { class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -92,6 +88,14 @@ class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {}; 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 a560a9ab40..301d763485 100644 --- a/test/js/samples/collapses-text-around-comments/expected-bundle.js +++ b/test/js/samples/collapses-text-around-comments/expected-bundle.js @@ -73,11 +73,7 @@ class Base { class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -100,6 +96,14 @@ class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {}; diff --git a/test/js/samples/component-static-immutable/expected-bundle.js b/test/js/samples/component-static-immutable/expected-bundle.js index 629fdb91ae..99898b6e09 100644 --- a/test/js/samples/component-static-immutable/expected-bundle.js +++ b/test/js/samples/component-static-immutable/expected-bundle.js @@ -53,11 +53,7 @@ class Base { class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -80,6 +76,14 @@ class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {}; diff --git a/test/js/samples/component-static-immutable2/expected-bundle.js b/test/js/samples/component-static-immutable2/expected-bundle.js index 629fdb91ae..99898b6e09 100644 --- a/test/js/samples/component-static-immutable2/expected-bundle.js +++ b/test/js/samples/component-static-immutable2/expected-bundle.js @@ -53,11 +53,7 @@ class Base { class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -80,6 +76,14 @@ class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {}; diff --git a/test/js/samples/component-static/expected-bundle.js b/test/js/samples/component-static/expected-bundle.js index 566baf5669..dd979af51e 100644 --- a/test/js/samples/component-static/expected-bundle.js +++ b/test/js/samples/component-static/expected-bundle.js @@ -53,11 +53,7 @@ class Base { class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -80,6 +76,14 @@ class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {}; diff --git a/test/js/samples/computed-collapsed-if/expected-bundle.js b/test/js/samples/computed-collapsed-if/expected-bundle.js index 378d292929..1c4e9fb1e6 100644 --- a/test/js/samples/computed-collapsed-if/expected-bundle.js +++ b/test/js/samples/computed-collapsed-if/expected-bundle.js @@ -53,11 +53,7 @@ class Base { class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -80,6 +76,14 @@ class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {}; diff --git a/test/js/samples/css-media-query/expected-bundle.js b/test/js/samples/css-media-query/expected-bundle.js index b28d3e0442..9740530796 100644 --- a/test/js/samples/css-media-query/expected-bundle.js +++ b/test/js/samples/css-media-query/expected-bundle.js @@ -69,11 +69,7 @@ class Base { class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -96,6 +92,14 @@ class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {}; 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 772a78de82..b772989469 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js @@ -65,11 +65,7 @@ class Base { class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -92,6 +88,14 @@ class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {}; @@ -162,6 +166,8 @@ function create_main_fragment(component, state) { class SvelteComponent extends HTMLElement { constructor(options = {}) { super(); + this._handlers = {}; + this._init.call(this, options); this._state = assign({}, options.data); this.attachShadow({ mode: 'open' }); @@ -184,8 +190,16 @@ class SvelteComponent extends HTMLElement { } } -customElements.define("custom-element", SvelteComponent); -assign(assign(SvelteComponent.prototype, Component.prototype), { +Object.getOwnPropertyNames(Component.prototype).forEach(name => { + SvelteComponent.prototype[name] = Component.prototype[name]; +}); + +assign(SvelteComponent.prototype, { + fire: Base.prototype.fire, + get: Base.prototype.get, + on: Base.prototype.on, + _differs: Base.prototype._differs, + _mount(target, anchor) { target.insertBefore(this, anchor); }, @@ -195,4 +209,6 @@ assign(assign(SvelteComponent.prototype, Component.prototype), { } }); +customElements.define("custom-element", SvelteComponent); + export default SvelteComponent; diff --git a/test/js/samples/css-shadow-dom-keyframes/expected.js b/test/js/samples/css-shadow-dom-keyframes/expected.js index 2487f11d97..431e4e0b0c 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { Component, assign, createElement, detachNode, insertNode, noop } from "svelte/shared.js"; +import { Base, Component, assign, createElement, detachNode, insertNode, noop } from "svelte/shared.js"; function create_main_fragment(component, state) { var div; @@ -28,6 +28,8 @@ function create_main_fragment(component, state) { class SvelteComponent extends HTMLElement { constructor(options = {}) { super(); + this._handlers = {}; + this._init.call(this, options); this._state = assign({}, options.data); this.attachShadow({ mode: 'open' }); @@ -50,8 +52,16 @@ class SvelteComponent extends HTMLElement { } } -customElements.define("custom-element", SvelteComponent); -assign(assign(SvelteComponent.prototype, Component.prototype), { +Object.getOwnPropertyNames(Component.prototype).forEach(name => { + SvelteComponent.prototype[name] = Component.prototype[name]; +}); + +assign(SvelteComponent.prototype, { + fire: Base.prototype.fire, + get: Base.prototype.get, + on: Base.prototype.on, + _differs: Base.prototype._differs, + _mount(target, anchor) { target.insertBefore(this, anchor); }, @@ -60,4 +70,6 @@ assign(assign(SvelteComponent.prototype, Component.prototype), { this.parentNode.removeChild(this); } }); + +customElements.define("custom-element", SvelteComponent); export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/deconflict-builtins/expected-bundle.js b/test/js/samples/deconflict-builtins/expected-bundle.js index 768107650d..5cd3fb63a1 100644 --- a/test/js/samples/deconflict-builtins/expected-bundle.js +++ b/test/js/samples/deconflict-builtins/expected-bundle.js @@ -83,11 +83,7 @@ class Base { class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -110,6 +106,14 @@ class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {}; diff --git a/test/js/samples/deconflict-globals/expected-bundle.js b/test/js/samples/deconflict-globals/expected-bundle.js index 9a46bec4b4..1bb8e1cb15 100644 --- a/test/js/samples/deconflict-globals/expected-bundle.js +++ b/test/js/samples/deconflict-globals/expected-bundle.js @@ -53,11 +53,7 @@ class Base { class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -80,6 +76,14 @@ class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {}; diff --git a/test/js/samples/dev-warning-missing-data-computed/expected-bundle.js b/test/js/samples/dev-warning-missing-data-computed/expected-bundle.js index 34cb7a388b..9ca15e534e 100644 --- a/test/js/samples/dev-warning-missing-data-computed/expected-bundle.js +++ b/test/js/samples/dev-warning-missing-data-computed/expected-bundle.js @@ -73,11 +73,7 @@ class Base { class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -100,6 +96,14 @@ class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {}; @@ -134,6 +138,14 @@ class Component extends Base { } class ComponentDev extends Component { + constructor(options) { + if (!options || (!options.target && !options.root)) { + throw new Error(`'target' is a required option`); + } + + super(options); + } + destroy(detach) { super.destroy(detach); this.destroy = () => { @@ -205,7 +217,6 @@ class SvelteComponent extends ComponentDev { constructor(options) { super(options); this._debugName = ''; - if (!options || (!options.target && !options.root)) throw new Error("'target' is a required option"); this._state = assign({ Math : Math }, options.data); this._recompute({ foo: 1 }, this._state); if (!('foo' in this._state)) console.warn(" was created without expected data property 'foo'"); diff --git a/test/js/samples/dev-warning-missing-data-computed/expected.js b/test/js/samples/dev-warning-missing-data-computed/expected.js index f01bfb8547..5f59f4ad2f 100644 --- a/test/js/samples/dev-warning-missing-data-computed/expected.js +++ b/test/js/samples/dev-warning-missing-data-computed/expected.js @@ -45,7 +45,6 @@ class SvelteComponent extends ComponentDev { constructor(options) { super(options); this._debugName = ''; - if (!options || (!options.target && !options.root)) throw new Error("'target' is a required option"); this._state = assign({ Math : Math }, options.data); this._recompute({ foo: 1 }, this._state); if (!('foo' in this._state)) console.warn(" was created without expected data property 'foo'"); diff --git a/test/js/samples/do-use-dataset/expected-bundle.js b/test/js/samples/do-use-dataset/expected-bundle.js index 18b24b0bdb..0a1590ef97 100644 --- a/test/js/samples/do-use-dataset/expected-bundle.js +++ b/test/js/samples/do-use-dataset/expected-bundle.js @@ -69,11 +69,7 @@ class Base { class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -96,6 +92,14 @@ class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {}; diff --git a/test/js/samples/dont-use-dataset-in-legacy/expected-bundle.js b/test/js/samples/dont-use-dataset-in-legacy/expected-bundle.js index 5adcc498bd..c52d1e46af 100644 --- a/test/js/samples/dont-use-dataset-in-legacy/expected-bundle.js +++ b/test/js/samples/dont-use-dataset-in-legacy/expected-bundle.js @@ -73,11 +73,7 @@ class Base { class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -100,6 +96,14 @@ class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {}; diff --git a/test/js/samples/dont-use-dataset-in-svg/expected-bundle.js b/test/js/samples/dont-use-dataset-in-svg/expected-bundle.js index f1bbc9b54b..e8a1b20748 100644 --- a/test/js/samples/dont-use-dataset-in-svg/expected-bundle.js +++ b/test/js/samples/dont-use-dataset-in-svg/expected-bundle.js @@ -73,11 +73,7 @@ class Base { class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -100,6 +96,14 @@ class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {}; 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 6062af65f7..644030d9c0 100644 --- a/test/js/samples/each-block-changed-check/expected-bundle.js +++ b/test/js/samples/each-block-changed-check/expected-bundle.js @@ -85,11 +85,7 @@ class Base { class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -112,6 +108,14 @@ class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {}; diff --git a/test/js/samples/event-handlers-custom/expected-bundle.js b/test/js/samples/event-handlers-custom/expected-bundle.js index 7c84b614e9..42c74274e4 100644 --- a/test/js/samples/event-handlers-custom/expected-bundle.js +++ b/test/js/samples/event-handlers-custom/expected-bundle.js @@ -65,11 +65,7 @@ class Base { class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -92,6 +88,14 @@ class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {}; diff --git a/test/js/samples/head-no-whitespace/expected-bundle.js b/test/js/samples/head-no-whitespace/expected-bundle.js index 06df9d7a23..1c249b5e36 100644 --- a/test/js/samples/head-no-whitespace/expected-bundle.js +++ b/test/js/samples/head-no-whitespace/expected-bundle.js @@ -65,11 +65,7 @@ class Base { class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -92,6 +88,14 @@ class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {}; 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 51829be7ed..d136aec41e 100644 --- a/test/js/samples/if-block-no-update/expected-bundle.js +++ b/test/js/samples/if-block-no-update/expected-bundle.js @@ -69,11 +69,7 @@ class Base { class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -96,6 +92,14 @@ class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {}; diff --git a/test/js/samples/if-block-simple/expected-bundle.js b/test/js/samples/if-block-simple/expected-bundle.js index d60da67652..d50825b0dc 100644 --- a/test/js/samples/if-block-simple/expected-bundle.js +++ b/test/js/samples/if-block-simple/expected-bundle.js @@ -69,11 +69,7 @@ class Base { class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -96,6 +92,14 @@ class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {}; 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 9bac3d0f5c..f1ea22c66b 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-multiple/expected-bundle.js @@ -69,11 +69,7 @@ class Base { class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -96,6 +92,14 @@ class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {}; 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 39a7a07416..63fd122d37 100644 --- a/test/js/samples/inline-style-optimized-url/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-url/expected-bundle.js @@ -69,11 +69,7 @@ class Base { class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -96,6 +92,14 @@ class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {}; diff --git a/test/js/samples/inline-style-optimized/expected-bundle.js b/test/js/samples/inline-style-optimized/expected-bundle.js index ee16d01111..fc4c0c7e7a 100644 --- a/test/js/samples/inline-style-optimized/expected-bundle.js +++ b/test/js/samples/inline-style-optimized/expected-bundle.js @@ -69,11 +69,7 @@ class Base { class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -96,6 +92,14 @@ class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {}; diff --git a/test/js/samples/inline-style-unoptimized/expected-bundle.js b/test/js/samples/inline-style-unoptimized/expected-bundle.js index 9d166cfae1..408622931e 100644 --- a/test/js/samples/inline-style-unoptimized/expected-bundle.js +++ b/test/js/samples/inline-style-unoptimized/expected-bundle.js @@ -69,11 +69,7 @@ class Base { class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -96,6 +92,14 @@ class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {}; 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 33186f7766..a8c94e4aa7 100644 --- a/test/js/samples/input-without-blowback-guard/expected-bundle.js +++ b/test/js/samples/input-without-blowback-guard/expected-bundle.js @@ -77,11 +77,7 @@ class Base { class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -104,6 +100,14 @@ class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {}; diff --git a/test/js/samples/legacy-input-type/expected-bundle.js b/test/js/samples/legacy-input-type/expected-bundle.js index 9967d0adfa..2483c6329e 100644 --- a/test/js/samples/legacy-input-type/expected-bundle.js +++ b/test/js/samples/legacy-input-type/expected-bundle.js @@ -71,11 +71,7 @@ class Base { class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -98,6 +94,14 @@ class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {}; diff --git a/test/js/samples/media-bindings/expected-bundle.js b/test/js/samples/media-bindings/expected-bundle.js index 86cdf03519..eef1e702d8 100644 --- a/test/js/samples/media-bindings/expected-bundle.js +++ b/test/js/samples/media-bindings/expected-bundle.js @@ -81,11 +81,7 @@ class Base { class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -108,6 +104,14 @@ class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {}; diff --git a/test/js/samples/non-imported-component/expected-bundle.js b/test/js/samples/non-imported-component/expected-bundle.js index f10b7ab3fb..81a7540dc1 100644 --- a/test/js/samples/non-imported-component/expected-bundle.js +++ b/test/js/samples/non-imported-component/expected-bundle.js @@ -67,11 +67,7 @@ class Base { class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -94,6 +90,14 @@ class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {}; diff --git a/test/js/samples/setup-method/expected-bundle.js b/test/js/samples/setup-method/expected-bundle.js index fb56f8acb9..607d633226 100644 --- a/test/js/samples/setup-method/expected-bundle.js +++ b/test/js/samples/setup-method/expected-bundle.js @@ -53,11 +53,7 @@ class Base { class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -80,6 +76,14 @@ class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {}; diff --git a/test/js/samples/svg-title/expected-bundle.js b/test/js/samples/svg-title/expected-bundle.js index 5293239c69..8ba137a500 100644 --- a/test/js/samples/svg-title/expected-bundle.js +++ b/test/js/samples/svg-title/expected-bundle.js @@ -73,11 +73,7 @@ class Base { class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -100,6 +96,14 @@ class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {}; diff --git a/test/js/samples/title/expected-bundle.js b/test/js/samples/title/expected-bundle.js index acbf1fb357..8e75f1e4d6 100644 --- a/test/js/samples/title/expected-bundle.js +++ b/test/js/samples/title/expected-bundle.js @@ -53,11 +53,7 @@ class Base { class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -80,6 +76,14 @@ class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {}; 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 1c56050833..53b53a7dba 100644 --- a/test/js/samples/use-elements-as-anchors/expected-bundle.js +++ b/test/js/samples/use-elements-as-anchors/expected-bundle.js @@ -77,11 +77,7 @@ class Base { class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -104,6 +100,14 @@ class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {}; diff --git a/test/js/samples/window-binding-scroll/expected-bundle.js b/test/js/samples/window-binding-scroll/expected-bundle.js index 7a91007308..3581e25a03 100644 --- a/test/js/samples/window-binding-scroll/expected-bundle.js +++ b/test/js/samples/window-binding-scroll/expected-bundle.js @@ -73,11 +73,7 @@ class Base { class Component extends Base { constructor(options) { super(); - this._bind = options._bind; - - this.options = options; - this.root = options.root || this; - this.store = this.root.store || options.store; + this._init(options); } destroy(detach) { @@ -100,6 +96,14 @@ class Component extends Base { this.root._lock = false; } + _init(options) { + this._bind = options._bind; + + this.options = options; + this.root = options.root || this; + this.store = this.root.store || options.store; + } + _set(newState) { const previous = this._state; const changed = {};