Merge pull request #856 from sveltejs/remove-is-initial

remove isInitial check on recompute
pull/7738/head
Rich Harris 8 years ago committed by GitHub
commit 86d6e91920

@ -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;`)}

@ -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);

@ -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);

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

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

@ -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);

@ -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);

@ -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);

@ -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);

@ -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);

@ -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);

@ -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);

@ -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);

@ -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);

@ -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);

@ -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);

@ -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);

@ -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);

@ -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);

@ -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);

@ -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);

@ -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);

@ -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);

Loading…
Cancel
Save