diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts index 3a20f1b549..3aa44d8f93 100644 --- a/src/generators/dom/index.ts +++ b/src/generators/dom/index.ts @@ -78,9 +78,14 @@ export default function dom( const builder = new CodeBuilder(); const computationBuilder = new CodeBuilder(); + const computationDeps = new Set(); if (computations.length) { computations.forEach(({ key, deps }) => { + deps.forEach(dep => { + computationDeps.add(dep); + }); + if (generator.readonly.has(key)) { // <:Window> bindings throw new Error( @@ -90,11 +95,11 @@ export default function dom( generator.readonly.add(key); - const condition = `isInitial || ${deps.map(dep => `changed.${dep}`).join(' || ')}`; + const condition = `${deps.map(dep => `changed.${dep}`).join(' || ')}`; - const statement = `if (@differs((state.${key} = @template.computed.${key}(${deps + const statement = `if (@differs(state.${key}, (state.${key} = @template.computed.${key}(${deps .map(dep => `state.${dep}`) - .join(', ')})), oldState.${key})) changed.${key} = true;`; + .join(', ')})))) changed.${key} = true;`; computationBuilder.addConditional(condition, statement); }); @@ -160,7 +165,7 @@ export default function dom( ? `@assign(@template.data(), options.data)` : `options.data || {}`}; ${generator.metaBindings} - ${computations.length && `this._recompute({}, this._state, {}, true);`} + ${computations.length && `this._recompute({ ${Array.from(computationDeps).map(dep => `${dep}: 1`).join(', ')} }, this._state);`} ${options.dev && Array.from(generator.expectedProperties).map( prop => @@ -298,7 +303,7 @@ export default function dom( `} ${computations.length ? deindent` - ${name}.prototype._recompute = function _recompute(changed, state, oldState, isInitial) { + ${name}.prototype._recompute = function _recompute(changed, state) { ${computationBuilder} } ` : (!sharedPath && `${name}.prototype._recompute = @noop;`)} diff --git a/src/shared/index.js b/src/shared/index.js index dcc2895831..c2e14744f3 100644 --- a/src/shared/index.js +++ b/src/shared/index.js @@ -155,7 +155,7 @@ export function _set(newState) { if (!dirty) return; this._state = assign({}, oldState, newState); - this._recompute(changed, this._state, oldState, false); + this._recompute(changed, this._state); if (this._bind) this._bind(changed, this._state); dispatchObservers(this, this._observers.pre, changed, this._state, oldState); this._fragment.update(changed, this._state); 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 2be3368d2f..f144e884aa 100644 --- a/test/js/samples/collapses-text-around-comments/expected-bundle.js +++ b/test/js/samples/collapses-text-around-comments/expected-bundle.js @@ -156,7 +156,7 @@ function _set(newState) { if (!dirty) return; this._state = assign({}, oldState, newState); - this._recompute(changed, this._state, oldState, false); + this._recompute(changed, this._state); if (this._bind) this._bind(changed, this._state); dispatchObservers(this, this._observers.pre, changed, this._state, oldState); this._fragment.update(changed, this._state); diff --git a/test/js/samples/computed-collapsed-if/expected-bundle.js b/test/js/samples/computed-collapsed-if/expected-bundle.js index 45165f32f2..752455d407 100644 --- a/test/js/samples/computed-collapsed-if/expected-bundle.js +++ b/test/js/samples/computed-collapsed-if/expected-bundle.js @@ -132,7 +132,7 @@ function _set(newState) { if (!dirty) return; this._state = assign({}, oldState, newState); - this._recompute(changed, this._state, oldState, false); + this._recompute(changed, this._state); if (this._bind) this._bind(changed, this._state); dispatchObservers(this, this._observers.pre, changed, this._state, oldState); this._fragment.update(changed, this._state); @@ -194,7 +194,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); this._state = options.data || {}; - this._recompute({}, this._state, {}, true); + this._recompute({ x: 1 }, this._state); this._fragment = create_main_fragment(this._state, this); @@ -206,10 +206,10 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -SvelteComponent.prototype._recompute = function _recompute(changed, state, oldState, isInitial) { - if (isInitial || changed.x) { - if (differs((state.a = template.computed.a(state.x)), oldState.a)) changed.a = true; - if (differs((state.b = template.computed.b(state.x)), oldState.b)) changed.b = true; +SvelteComponent.prototype._recompute = function _recompute(changed, state) { + if (changed.x) { + if (differs(state.a, (state.a = template.computed.a(state.x)))) changed.a = true; + if (differs(state.b, (state.b = template.computed.b(state.x)))) changed.b = true; } }; diff --git a/test/js/samples/computed-collapsed-if/expected.js b/test/js/samples/computed-collapsed-if/expected.js index 9285387573..097e5557c8 100644 --- a/test/js/samples/computed-collapsed-if/expected.js +++ b/test/js/samples/computed-collapsed-if/expected.js @@ -29,7 +29,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); this._state = options.data || {}; - this._recompute({}, this._state, {}, true); + this._recompute({ x: 1 }, this._state); this._fragment = create_main_fragment(this._state, this); @@ -41,10 +41,10 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -SvelteComponent.prototype._recompute = function _recompute(changed, state, oldState, isInitial) { - if (isInitial || changed.x) { - if (differs((state.a = template.computed.a(state.x)), oldState.a)) changed.a = true; - if (differs((state.b = template.computed.b(state.x)), oldState.b)) changed.b = true; +SvelteComponent.prototype._recompute = function _recompute(changed, state) { + if (changed.x) { + if (differs(state.a, (state.a = template.computed.a(state.x)))) changed.a = true; + if (differs(state.b, (state.b = template.computed.b(state.x)))) changed.b = true; } } diff --git a/test/js/samples/css-media-query/expected-bundle.js b/test/js/samples/css-media-query/expected-bundle.js index 5dbf391326..8cc7e465d1 100644 --- a/test/js/samples/css-media-query/expected-bundle.js +++ b/test/js/samples/css-media-query/expected-bundle.js @@ -152,7 +152,7 @@ function _set(newState) { if (!dirty) return; this._state = assign({}, oldState, newState); - this._recompute(changed, this._state, oldState, false); + this._recompute(changed, this._state); if (this._bind) this._bind(changed, this._state); dispatchObservers(this, this._observers.pre, changed, this._state, oldState); this._fragment.update(changed, this._state); 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 9929e79d72..4761ffe62c 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js @@ -152,7 +152,7 @@ function _set(newState) { if (!dirty) return; this._state = assign({}, oldState, newState); - this._recompute(changed, this._state, oldState, false); + this._recompute(changed, this._state); if (this._bind) this._bind(changed, this._state); dispatchObservers(this, this._observers.pre, changed, this._state, oldState); this._fragment.update(changed, this._state); 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 c75cdfd1c5..5f73756b77 100644 --- a/test/js/samples/each-block-changed-check/expected-bundle.js +++ b/test/js/samples/each-block-changed-check/expected-bundle.js @@ -165,7 +165,7 @@ function _set(newState) { if (!dirty) return; this._state = assign({}, oldState, newState); - this._recompute(changed, this._state, oldState, false); + this._recompute(changed, this._state); if (this._bind) this._bind(changed, this._state); dispatchObservers(this, this._observers.pre, changed, this._state, oldState); this._fragment.update(changed, this._state); diff --git a/test/js/samples/event-handlers-custom/expected-bundle.js b/test/js/samples/event-handlers-custom/expected-bundle.js index 7fa738daba..f779357293 100644 --- a/test/js/samples/event-handlers-custom/expected-bundle.js +++ b/test/js/samples/event-handlers-custom/expected-bundle.js @@ -152,7 +152,7 @@ function _set(newState) { if (!dirty) return; this._state = assign({}, oldState, newState); - this._recompute(changed, this._state, oldState, false); + this._recompute(changed, this._state); if (this._bind) this._bind(changed, this._state); dispatchObservers(this, this._observers.pre, changed, this._state, oldState); this._fragment.update(changed, this._state); 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 4511aed851..d68a947cdb 100644 --- a/test/js/samples/if-block-no-update/expected-bundle.js +++ b/test/js/samples/if-block-no-update/expected-bundle.js @@ -156,7 +156,7 @@ function _set(newState) { if (!dirty) return; this._state = assign({}, oldState, newState); - this._recompute(changed, this._state, oldState, false); + this._recompute(changed, this._state); if (this._bind) this._bind(changed, this._state); dispatchObservers(this, this._observers.pre, changed, this._state, oldState); this._fragment.update(changed, this._state); diff --git a/test/js/samples/if-block-simple/expected-bundle.js b/test/js/samples/if-block-simple/expected-bundle.js index c377fd81dd..45ddba0cff 100644 --- a/test/js/samples/if-block-simple/expected-bundle.js +++ b/test/js/samples/if-block-simple/expected-bundle.js @@ -156,7 +156,7 @@ function _set(newState) { if (!dirty) return; this._state = assign({}, oldState, newState); - this._recompute(changed, this._state, oldState, false); + this._recompute(changed, this._state); if (this._bind) this._bind(changed, this._state); dispatchObservers(this, this._observers.pre, changed, this._state, oldState); this._fragment.update(changed, this._state); 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 65f560df59..15972de8db 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-multiple/expected-bundle.js @@ -148,7 +148,7 @@ function _set(newState) { if (!dirty) return; this._state = assign({}, oldState, newState); - this._recompute(changed, this._state, oldState, false); + this._recompute(changed, this._state); if (this._bind) this._bind(changed, this._state); dispatchObservers(this, this._observers.pre, changed, this._state, oldState); this._fragment.update(changed, this._state); 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 c94df83db0..b9fffb2f15 100644 --- a/test/js/samples/inline-style-optimized-url/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-url/expected-bundle.js @@ -148,7 +148,7 @@ function _set(newState) { if (!dirty) return; this._state = assign({}, oldState, newState); - this._recompute(changed, this._state, oldState, false); + this._recompute(changed, this._state); if (this._bind) this._bind(changed, this._state); dispatchObservers(this, this._observers.pre, changed, this._state, oldState); this._fragment.update(changed, this._state); diff --git a/test/js/samples/inline-style-optimized/expected-bundle.js b/test/js/samples/inline-style-optimized/expected-bundle.js index 328cfdac1e..385aaa0c30 100644 --- a/test/js/samples/inline-style-optimized/expected-bundle.js +++ b/test/js/samples/inline-style-optimized/expected-bundle.js @@ -148,7 +148,7 @@ function _set(newState) { if (!dirty) return; this._state = assign({}, oldState, newState); - this._recompute(changed, this._state, oldState, false); + this._recompute(changed, this._state); if (this._bind) this._bind(changed, this._state); dispatchObservers(this, this._observers.pre, changed, this._state, oldState); this._fragment.update(changed, this._state); diff --git a/test/js/samples/inline-style-unoptimized/expected-bundle.js b/test/js/samples/inline-style-unoptimized/expected-bundle.js index 14d890c2a5..f031e6c0e2 100644 --- a/test/js/samples/inline-style-unoptimized/expected-bundle.js +++ b/test/js/samples/inline-style-unoptimized/expected-bundle.js @@ -148,7 +148,7 @@ function _set(newState) { if (!dirty) return; this._state = assign({}, oldState, newState); - this._recompute(changed, this._state, oldState, false); + this._recompute(changed, this._state); if (this._bind) this._bind(changed, this._state); dispatchObservers(this, this._observers.pre, changed, this._state, oldState); this._fragment.update(changed, this._state); 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 63a8e23b42..99ce19c0bf 100644 --- a/test/js/samples/input-without-blowback-guard/expected-bundle.js +++ b/test/js/samples/input-without-blowback-guard/expected-bundle.js @@ -152,7 +152,7 @@ function _set(newState) { if (!dirty) return; this._state = assign({}, oldState, newState); - this._recompute(changed, this._state, oldState, false); + this._recompute(changed, this._state); if (this._bind) this._bind(changed, this._state); dispatchObservers(this, this._observers.pre, changed, this._state, oldState); this._fragment.update(changed, this._state); diff --git a/test/js/samples/legacy-input-type/expected-bundle.js b/test/js/samples/legacy-input-type/expected-bundle.js index d480bb9018..35a5253a26 100644 --- a/test/js/samples/legacy-input-type/expected-bundle.js +++ b/test/js/samples/legacy-input-type/expected-bundle.js @@ -150,7 +150,7 @@ function _set(newState) { if (!dirty) return; this._state = assign({}, oldState, newState); - this._recompute(changed, this._state, oldState, false); + this._recompute(changed, this._state); if (this._bind) this._bind(changed, this._state); dispatchObservers(this, this._observers.pre, changed, this._state, oldState); this._fragment.update(changed, this._state); diff --git a/test/js/samples/legacy-quote-class/expected-bundle.js b/test/js/samples/legacy-quote-class/expected-bundle.js index b0a3df7502..a3edb24252 100644 --- a/test/js/samples/legacy-quote-class/expected-bundle.js +++ b/test/js/samples/legacy-quote-class/expected-bundle.js @@ -167,7 +167,7 @@ function _set(newState) { if (!dirty) return; this._state = assign({}, oldState, newState); - this._recompute(changed, this._state, oldState, false); + this._recompute(changed, this._state); if (this._bind) this._bind(changed, this._state); dispatchObservers(this, this._observers.pre, changed, this._state, oldState); this._fragment.update(changed, this._state); diff --git a/test/js/samples/media-bindings/expected-bundle.js b/test/js/samples/media-bindings/expected-bundle.js index 4ff47469bf..08e8a09d7c 100644 --- a/test/js/samples/media-bindings/expected-bundle.js +++ b/test/js/samples/media-bindings/expected-bundle.js @@ -160,7 +160,7 @@ function _set(newState) { if (!dirty) return; this._state = assign({}, oldState, newState); - this._recompute(changed, this._state, oldState, false); + this._recompute(changed, this._state); if (this._bind) this._bind(changed, this._state); dispatchObservers(this, this._observers.pre, changed, this._state, oldState); this._fragment.update(changed, this._state); diff --git a/test/js/samples/non-imported-component/expected-bundle.js b/test/js/samples/non-imported-component/expected-bundle.js index 3a1bab7160..817ab2c4f8 100644 --- a/test/js/samples/non-imported-component/expected-bundle.js +++ b/test/js/samples/non-imported-component/expected-bundle.js @@ -146,7 +146,7 @@ function _set(newState) { if (!dirty) return; this._state = assign({}, oldState, newState); - this._recompute(changed, this._state, oldState, false); + this._recompute(changed, this._state); if (this._bind) this._bind(changed, this._state); dispatchObservers(this, this._observers.pre, changed, this._state, oldState); this._fragment.update(changed, this._state); diff --git a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js index 5edc971ed1..2bec66e3e1 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js @@ -132,7 +132,7 @@ function _set(newState) { if (!dirty) return; this._state = assign({}, oldState, newState); - this._recompute(changed, this._state, oldState, false); + this._recompute(changed, this._state); if (this._bind) this._bind(changed, this._state); dispatchObservers(this, this._observers.pre, changed, this._state, oldState); this._fragment.update(changed, this._state); diff --git a/test/js/samples/setup-method/expected-bundle.js b/test/js/samples/setup-method/expected-bundle.js index 0bdb4ad0f1..0752ea7839 100644 --- a/test/js/samples/setup-method/expected-bundle.js +++ b/test/js/samples/setup-method/expected-bundle.js @@ -132,7 +132,7 @@ function _set(newState) { if (!dirty) return; this._state = assign({}, oldState, newState); - this._recompute(changed, this._state, oldState, false); + this._recompute(changed, this._state); if (this._bind) this._bind(changed, this._state); dispatchObservers(this, this._observers.pre, changed, this._state, oldState); this._fragment.update(changed, this._state); 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 16d52ebb40..5a9b918376 100644 --- a/test/js/samples/use-elements-as-anchors/expected-bundle.js +++ b/test/js/samples/use-elements-as-anchors/expected-bundle.js @@ -156,7 +156,7 @@ function _set(newState) { if (!dirty) return; this._state = assign({}, oldState, newState); - this._recompute(changed, this._state, oldState, false); + this._recompute(changed, this._state); if (this._bind) this._bind(changed, this._state); dispatchObservers(this, this._observers.pre, changed, this._state, oldState); this._fragment.update(changed, this._state);