From 544f17fba33ed477bee87eae2e4cebb44c0bca4c Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 17 Sep 2017 12:21:26 -0400 Subject: [PATCH 1/3] remove isInitial check on recompute --- src/generators/dom/index.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts index 8d82fef182..f2ef1d32bf 100644 --- a/src/generators/dom/index.ts +++ b/src/generators/dom/index.ts @@ -77,9 +77,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( @@ -89,7 +94,7 @@ 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 .map(dep => `state.${dep}`) @@ -159,7 +164,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 => @@ -306,7 +311,7 @@ export default function dom( `} ${computations.length ? deindent` - ${name}.prototype._recompute = function _recompute(changed, state, oldState, isInitial) { + ${name}.prototype._recompute = function _recompute(changed, state, oldState) { ${computationBuilder} } ` : (!sharedPath && `${name}.prototype._recompute = @noop;`)} From b9492905a14ba48913c0502de4ee41eb2757db67 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 17 Sep 2017 12:29:01 -0400 Subject: [PATCH 2/3] remove oldState from recompute --- src/generators/dom/index.ts | 8 ++++---- src/shared/index.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts index 768aff7a4e..3aa44d8f93 100644 --- a/src/generators/dom/index.ts +++ b/src/generators/dom/index.ts @@ -97,9 +97,9 @@ export default function dom( 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); }); @@ -165,7 +165,7 @@ export default function dom( ? `@assign(@template.data(), options.data)` : `options.data || {}`}; ${generator.metaBindings} - ${computations.length && `this._recompute({ ${Array.from(computationDeps).map(dep => `${dep}: 1`).join(', ')} }, this._state, {});`} + ${computations.length && `this._recompute({ ${Array.from(computationDeps).map(dep => `${dep}: 1`).join(', ')} }, this._state);`} ${options.dev && Array.from(generator.expectedProperties).map( prop => @@ -303,7 +303,7 @@ export default function dom( `} ${computations.length ? deindent` - ${name}.prototype._recompute = function _recompute(changed, state, oldState) { + ${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); From c4623c8e20f38b2507aee0d5637207eb3def6238 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 17 Sep 2017 12:29:11 -0400 Subject: [PATCH 3/3] update snapshot tests --- .../expected-bundle.js | 2 +- .../samples/computed-collapsed-if/expected-bundle.js | 12 ++++++------ test/js/samples/computed-collapsed-if/expected.js | 10 +++++----- test/js/samples/css-media-query/expected-bundle.js | 2 +- .../css-shadow-dom-keyframes/expected-bundle.js | 2 +- .../each-block-changed-check/expected-bundle.js | 2 +- .../samples/event-handlers-custom/expected-bundle.js | 2 +- .../js/samples/if-block-no-update/expected-bundle.js | 2 +- test/js/samples/if-block-simple/expected-bundle.js | 2 +- .../expected-bundle.js | 2 +- .../inline-style-optimized-url/expected-bundle.js | 2 +- .../inline-style-optimized/expected-bundle.js | 2 +- .../inline-style-unoptimized/expected-bundle.js | 2 +- .../input-without-blowback-guard/expected-bundle.js | 2 +- test/js/samples/legacy-input-type/expected-bundle.js | 2 +- .../js/samples/legacy-quote-class/expected-bundle.js | 2 +- test/js/samples/media-bindings/expected-bundle.js | 2 +- .../non-imported-component/expected-bundle.js | 2 +- .../onrender-onteardown-rewritten/expected-bundle.js | 2 +- test/js/samples/setup-method/expected-bundle.js | 2 +- .../use-elements-as-anchors/expected-bundle.js | 2 +- 21 files changed, 30 insertions(+), 30 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 3ad254d588..4b70bc1de2 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 51eaaf39bc..3811d054c7 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 9a0ef1c2b4..ffc38a430e 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 9ffeb2f221..f9b1e0f8a5 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 7e04a00dd9..123766a5ac 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 f69d691333..368101ee8b 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 022592786b..c14c756674 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 8f91bf4175..d205e772d7 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 7007f2830f..16fa36281f 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 6142c14afd..c160d39545 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 2ff763246a..3f06dbfdd3 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 554be56ba4..c04901fea3 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 5ab9d5db50..8573e26804 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 b1c6c3b8e5..1760bc77e8 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 c950e0ddb1..3ac160383e 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 9d0e225527..8fc9928e83 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 ce26e1ac63..0c7a3ed405 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 f1f284a01f..eb36597ce1 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 c1556145d3..5f8b721a98 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 a5c4ff68f8..8eb45ef465 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 ae00877549..fbbcd4a580 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);