Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove isInitial check on recompute #856

Merged
merged 4 commits into from
Sep 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/generators/dom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
});
Expand Down Expand Up @@ -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 =>
Expand Down Expand Up @@ -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;`)}
Expand Down
2 changes: 1 addition & 1 deletion src/shared/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions test/js/samples/computed-collapsed-if/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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;
}
};

Expand Down
10 changes: 5 additions & 5 deletions test/js/samples/computed-collapsed-if/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/js/samples/css-media-query/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/js/samples/event-handlers-custom/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/js/samples/if-block-no-update/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/js/samples/if-block-simple/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/js/samples/inline-style-optimized/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/js/samples/legacy-input-type/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/js/samples/legacy-quote-class/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/js/samples/media-bindings/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/js/samples/non-imported-component/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/js/samples/setup-method/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/js/samples/use-elements-as-anchors/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down