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 e52f943862..11d4b52fe9 100644 --- a/test/js/samples/collapses-text-around-comments/expected-bundle.js +++ b/test/js/samples/collapses-text-around-comments/expected-bundle.js @@ -52,25 +52,23 @@ function differs(a, b) { return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -function dispatchObservers(component, group, newState, oldState) { +function dispatchObservers(component, group, changed, newState, oldState) { for (var key in group) { - if (!(key in newState)) continue; + if (!(key in changed)) continue; var newValue = newState[key]; var oldValue = oldState[key]; - if (differs(newValue, oldValue)) { - var callbacks = group[key]; - if (!callbacks) continue; + var callbacks = group[key]; + if (!callbacks) continue; - for (var i = 0; i < callbacks.length; i += 1) { - var callback = callbacks[i]; - if (callback.__calling) continue; + for (var i = 0; i < callbacks.length; i += 1) { + var callback = callbacks[i]; + if (callback.__calling) continue; - callback.__calling = true; - callback.call(component, newValue, oldValue); - callback.__calling = false; - } + callback.__calling = true; + callback.call(component, newValue, oldValue); + callback.__calling = false; } } } @@ -134,6 +132,23 @@ function set(newState) { this._root._lock = false; } +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign({}, oldState, newState); + this._recompute(changed, this._state, oldState, false); + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.update(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); +} + function callAll(fns) { while (fns && fns.length) fns.pop()(); } @@ -145,7 +160,9 @@ var proto = { observe: observe, on: on, set: set, - teardown: destroy + teardown: destroy, + _recompute: noop, + _set: _set }; var template = (function () { @@ -187,7 +204,7 @@ function create_main_fragment ( state, component ) { }, update: function ( changed, state ) { - if ( text_value !== ( text_value = state.foo ) ) { + if ( ( 'foo' in changed ) && text_value !== ( text_value = state.foo ) ) { text.data = text_value; } }, @@ -226,12 +243,4 @@ function SvelteComponent ( options ) { assign( SvelteComponent.prototype, proto ); -SvelteComponent.prototype._set = function _set ( newState ) { - var oldState = this._state; - this._state = assign( {}, oldState, newState ); - dispatchObservers( this, this._observers.pre, newState, oldState ); - this._fragment.update( newState, this._state ); - dispatchObservers( this, this._observers.post, newState, oldState ); -}; - export default SvelteComponent; diff --git a/test/js/samples/collapses-text-around-comments/expected.js b/test/js/samples/collapses-text-around-comments/expected.js index 5a3e3d52f6..15292cd526 100644 --- a/test/js/samples/collapses-text-around-comments/expected.js +++ b/test/js/samples/collapses-text-around-comments/expected.js @@ -1,4 +1,4 @@ -import { appendNode, assign, createElement, createText, detachNode, dispatchObservers, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; +import { appendNode, assign, createElement, createText, detachNode, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; var template = (function () { return { @@ -39,7 +39,7 @@ function create_main_fragment ( state, component ) { }, update: function ( changed, state ) { - if ( text_value !== ( text_value = state.foo ) ) { + if ( ( 'foo' in changed ) && text_value !== ( text_value = state.foo ) ) { text.data = text_value; } }, @@ -78,12 +78,4 @@ function SvelteComponent ( options ) { assign( SvelteComponent.prototype, proto ); -SvelteComponent.prototype._set = function _set ( newState ) { - var oldState = this._state; - this._state = assign( {}, oldState, newState ); - dispatchObservers( this, this._observers.pre, newState, oldState ); - this._fragment.update( newState, this._state ); - dispatchObservers( this, this._observers.post, newState, oldState ); -}; - export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/computed-collapsed-if/expected-bundle.js b/test/js/samples/computed-collapsed-if/expected-bundle.js index 0da5cdf32c..112d21f8d8 100644 --- a/test/js/samples/computed-collapsed-if/expected-bundle.js +++ b/test/js/samples/computed-collapsed-if/expected-bundle.js @@ -28,25 +28,23 @@ function differs(a, b) { return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -function dispatchObservers(component, group, newState, oldState) { +function dispatchObservers(component, group, changed, newState, oldState) { for (var key in group) { - if (!(key in newState)) continue; + if (!(key in changed)) continue; var newValue = newState[key]; var oldValue = oldState[key]; - if (differs(newValue, oldValue)) { - var callbacks = group[key]; - if (!callbacks) continue; + var callbacks = group[key]; + if (!callbacks) continue; - for (var i = 0; i < callbacks.length; i += 1) { - var callback = callbacks[i]; - if (callback.__calling) continue; + for (var i = 0; i < callbacks.length; i += 1) { + var callback = callbacks[i]; + if (callback.__calling) continue; - callback.__calling = true; - callback.call(component, newValue, oldValue); - callback.__calling = false; - } + callback.__calling = true; + callback.call(component, newValue, oldValue); + callback.__calling = false; } } } @@ -110,6 +108,23 @@ function set(newState) { this._root._lock = false; } +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign({}, oldState, newState); + this._recompute(changed, this._state, oldState, false); + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.update(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); +} + function callAll(fns) { while (fns && fns.length) fns.pop()(); } @@ -121,16 +136,11 @@ var proto = { observe: observe, on: on, set: set, - teardown: destroy + teardown: destroy, + _recompute: noop, + _set: _set }; -function recompute ( state, newState, oldState, isInitial ) { - if ( isInitial || ( 'x' in newState && differs( state.x, oldState.x ) ) ) { - state.a = newState.a = template.computed.a( state.x ); - state.b = newState.b = template.computed.b( state.x ); - } -} - var template = (function () { return { computed: { @@ -147,6 +157,8 @@ function create_main_fragment ( state, component ) { mount: noop, + update: noop, + unmount: noop, destroy: noop @@ -156,7 +168,7 @@ function create_main_fragment ( state, component ) { function SvelteComponent ( options ) { options = options || {}; this._state = options.data || {}; - recompute( this._state, this._state, {}, true ); + this._recompute( {}, this._state, {}, true ); this._observers = { pre: Object.create( null ), @@ -178,12 +190,11 @@ function SvelteComponent ( options ) { assign( SvelteComponent.prototype, proto ); -SvelteComponent.prototype._set = function _set ( newState ) { - var oldState = this._state; - this._state = assign( {}, oldState, newState ); - recompute( this._state, newState, oldState, false ); - dispatchObservers( this, this._observers.pre, newState, oldState ); - dispatchObservers( this, this._observers.post, newState, oldState ); +SvelteComponent.prototype._recompute = function _recompute ( changed, state, oldState, isInitial ) { + if ( isInitial || ( 'x' in changed ) ) { + 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; + } }; export default SvelteComponent; diff --git a/test/js/samples/computed-collapsed-if/expected.js b/test/js/samples/computed-collapsed-if/expected.js index a17e730122..edfca61b86 100644 --- a/test/js/samples/computed-collapsed-if/expected.js +++ b/test/js/samples/computed-collapsed-if/expected.js @@ -1,11 +1,4 @@ -import { assign, differs, dispatchObservers, noop, proto } from "svelte/shared.js"; - -function recompute ( state, newState, oldState, isInitial ) { - if ( isInitial || ( 'x' in newState && differs( state.x, oldState.x ) ) ) { - state.a = newState.a = template.computed.a( state.x ); - state.b = newState.b = template.computed.b( state.x ); - } -} +import { assign, differs, noop, proto } from "svelte/shared.js"; var template = (function () { return { @@ -23,6 +16,8 @@ function create_main_fragment ( state, component ) { mount: noop, + update: noop, + unmount: noop, destroy: noop @@ -32,7 +27,7 @@ function create_main_fragment ( state, component ) { function SvelteComponent ( options ) { options = options || {}; this._state = options.data || {}; - recompute( this._state, this._state, {}, true ); + this._recompute( {}, this._state, {}, true ); this._observers = { pre: Object.create( null ), @@ -54,12 +49,11 @@ function SvelteComponent ( options ) { assign( SvelteComponent.prototype, proto ); -SvelteComponent.prototype._set = function _set ( newState ) { - var oldState = this._state; - this._state = assign( {}, oldState, newState ); - recompute( this._state, newState, oldState, false ) - dispatchObservers( this, this._observers.pre, newState, oldState ); - dispatchObservers( this, this._observers.post, newState, oldState ); -}; +SvelteComponent.prototype._recompute = function _recompute ( changed, state, oldState, isInitial ) { + if ( isInitial || ( 'x' in changed ) ) { + 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; + } +} export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/css-media-query/expected-bundle.js b/test/js/samples/css-media-query/expected-bundle.js index 3324ebf9be..ee643bae65 100644 --- a/test/js/samples/css-media-query/expected-bundle.js +++ b/test/js/samples/css-media-query/expected-bundle.js @@ -48,25 +48,23 @@ function differs(a, b) { return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -function dispatchObservers(component, group, newState, oldState) { +function dispatchObservers(component, group, changed, newState, oldState) { for (var key in group) { - if (!(key in newState)) continue; + if (!(key in changed)) continue; var newValue = newState[key]; var oldValue = oldState[key]; - if (differs(newValue, oldValue)) { - var callbacks = group[key]; - if (!callbacks) continue; + var callbacks = group[key]; + if (!callbacks) continue; - for (var i = 0; i < callbacks.length; i += 1) { - var callback = callbacks[i]; - if (callback.__calling) continue; + for (var i = 0; i < callbacks.length; i += 1) { + var callback = callbacks[i]; + if (callback.__calling) continue; - callback.__calling = true; - callback.call(component, newValue, oldValue); - callback.__calling = false; - } + callback.__calling = true; + callback.call(component, newValue, oldValue); + callback.__calling = false; } } } @@ -130,6 +128,23 @@ function set(newState) { this._root._lock = false; } +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign({}, oldState, newState); + this._recompute(changed, this._state, oldState, false); + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.update(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); +} + function callAll(fns) { while (fns && fns.length) fns.pop()(); } @@ -141,7 +156,9 @@ var proto = { observe: observe, on: on, set: set, - teardown: destroy + teardown: destroy, + _recompute: noop, + _set: _set }; function encapsulateStyles ( node ) { @@ -172,6 +189,8 @@ function create_main_fragment ( state, component ) { insertNode( div, target, anchor ); }, + update: noop, + unmount: function () { detachNode( div ); }, @@ -206,11 +225,4 @@ function SvelteComponent ( options ) { assign( SvelteComponent.prototype, proto ); -SvelteComponent.prototype._set = function _set ( newState ) { - var oldState = this._state; - this._state = assign( {}, oldState, newState ); - dispatchObservers( this, this._observers.pre, newState, oldState ); - dispatchObservers( this, this._observers.post, newState, oldState ); -}; - export default SvelteComponent; diff --git a/test/js/samples/css-media-query/expected.js b/test/js/samples/css-media-query/expected.js index 72338bb55b..8fb4bde21a 100644 --- a/test/js/samples/css-media-query/expected.js +++ b/test/js/samples/css-media-query/expected.js @@ -1,4 +1,4 @@ -import { appendNode, assign, createElement, detachNode, dispatchObservers, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; +import { appendNode, assign, createElement, detachNode, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; function encapsulateStyles ( node ) { setAttribute( node, 'svelte-2363328337', '' ); @@ -28,6 +28,8 @@ function create_main_fragment ( state, component ) { insertNode( div, target, anchor ); }, + update: noop, + unmount: function () { detachNode( div ); }, @@ -62,11 +64,4 @@ function SvelteComponent ( options ) { assign( SvelteComponent.prototype, proto ); -SvelteComponent.prototype._set = function _set ( newState ) { - var oldState = this._state; - this._state = assign( {}, oldState, newState ); - dispatchObservers( this, this._observers.pre, newState, oldState ); - dispatchObservers( this, this._observers.post, newState, oldState ); -}; - export default SvelteComponent; \ No newline at end of file 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 aac78b9adb..13c79c6933 100644 --- a/test/js/samples/each-block-changed-check/expected-bundle.js +++ b/test/js/samples/each-block-changed-check/expected-bundle.js @@ -61,25 +61,23 @@ function differs(a, b) { return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -function dispatchObservers(component, group, newState, oldState) { +function dispatchObservers(component, group, changed, newState, oldState) { for (var key in group) { - if (!(key in newState)) continue; + if (!(key in changed)) continue; var newValue = newState[key]; var oldValue = oldState[key]; - if (differs(newValue, oldValue)) { - var callbacks = group[key]; - if (!callbacks) continue; + var callbacks = group[key]; + if (!callbacks) continue; - for (var i = 0; i < callbacks.length; i += 1) { - var callback = callbacks[i]; - if (callback.__calling) continue; + for (var i = 0; i < callbacks.length; i += 1) { + var callback = callbacks[i]; + if (callback.__calling) continue; - callback.__calling = true; - callback.call(component, newValue, oldValue); - callback.__calling = false; - } + callback.__calling = true; + callback.call(component, newValue, oldValue); + callback.__calling = false; } } } @@ -143,6 +141,23 @@ function set(newState) { this._root._lock = false; } +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign({}, oldState, newState); + this._recompute(changed, this._state, oldState, false); + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.update(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); +} + function callAll(fns) { while (fns && fns.length) fns.pop()(); } @@ -154,7 +169,9 @@ var proto = { observe: observe, on: on, set: set, - teardown: destroy + teardown: destroy, + _recompute: noop, + _set: _set }; function create_main_fragment ( state, component ) { @@ -210,7 +227,7 @@ function create_main_fragment ( state, component ) { each_block_iterations.length = each_block_value.length; } - if ( text_1_value !== ( text_1_value = state.foo ) ) { + if ( ( 'foo' in changed ) && text_1_value !== ( text_1_value = state.foo ) ) { text_1.data = text_1_value; } }, @@ -272,15 +289,11 @@ function create_each_block ( state, each_block_value, comment, i, component ) { }, update: function ( changed, state, each_block_value, comment, i ) { - if ( text_value !== ( text_value = i ) ) { - text.data = text_value; - } - - if ( text_2_value !== ( text_2_value = comment.author ) ) { + if ( ( 'comments' in changed ) && text_2_value !== ( text_2_value = comment.author ) ) { text_2.data = text_2_value; } - if ( text_4_value !== ( text_4_value = state.elapsed(comment.time, state.time) ) ) { + if ( ( 'elapsed' in changed || 'comments' in changed || 'time' in changed ) && text_4_value !== ( text_4_value = state.elapsed(comment.time, state.time) ) ) { text_4.data = text_4_value; } @@ -324,12 +337,4 @@ function SvelteComponent ( options ) { assign( SvelteComponent.prototype, proto ); -SvelteComponent.prototype._set = function _set ( newState ) { - var oldState = this._state; - this._state = assign( {}, oldState, newState ); - dispatchObservers( this, this._observers.pre, newState, oldState ); - this._fragment.update( newState, this._state ); - dispatchObservers( this, this._observers.post, newState, oldState ); -}; - export default SvelteComponent; diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js index e7683e0743..a7c1e31f92 100644 --- a/test/js/samples/each-block-changed-check/expected.js +++ b/test/js/samples/each-block-changed-check/expected.js @@ -1,4 +1,4 @@ -import { appendNode, assign, createElement, createText, destroyEach, detachBetween, detachNode, dispatchObservers, insertNode, noop, proto } from "svelte/shared.js"; +import { appendNode, assign, createElement, createText, destroyEach, detachBetween, detachNode, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment ( state, component ) { var text, p, text_1_value, text_1; @@ -53,7 +53,7 @@ function create_main_fragment ( state, component ) { each_block_iterations.length = each_block_value.length; } - if ( text_1_value !== ( text_1_value = state.foo ) ) { + if ( ( 'foo' in changed ) && text_1_value !== ( text_1_value = state.foo ) ) { text_1.data = text_1_value; } }, @@ -115,15 +115,11 @@ function create_each_block ( state, each_block_value, comment, i, component ) { }, update: function ( changed, state, each_block_value, comment, i ) { - if ( text_value !== ( text_value = i ) ) { - text.data = text_value; - } - - if ( text_2_value !== ( text_2_value = comment.author ) ) { + if ( ( 'comments' in changed ) && text_2_value !== ( text_2_value = comment.author ) ) { text_2.data = text_2_value; } - if ( text_4_value !== ( text_4_value = state.elapsed(comment.time, state.time) ) ) { + if ( ( 'elapsed' in changed || 'comments' in changed || 'time' in changed ) && text_4_value !== ( text_4_value = state.elapsed(comment.time, state.time) ) ) { text_4.data = text_4_value; } @@ -167,12 +163,4 @@ function SvelteComponent ( options ) { assign( SvelteComponent.prototype, proto ); -SvelteComponent.prototype._set = function _set ( newState ) { - var oldState = this._state; - this._state = assign( {}, oldState, newState ); - dispatchObservers( this, this._observers.pre, newState, oldState ); - this._fragment.update( newState, this._state ); - dispatchObservers( this, this._observers.post, newState, oldState ); -}; - export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/event-handlers-custom/expected-bundle.js b/test/js/samples/event-handlers-custom/expected-bundle.js index ed200a7b4c..dafef990c2 100644 --- a/test/js/samples/event-handlers-custom/expected-bundle.js +++ b/test/js/samples/event-handlers-custom/expected-bundle.js @@ -48,25 +48,23 @@ function differs(a, b) { return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -function dispatchObservers(component, group, newState, oldState) { +function dispatchObservers(component, group, changed, newState, oldState) { for (var key in group) { - if (!(key in newState)) continue; + if (!(key in changed)) continue; var newValue = newState[key]; var oldValue = oldState[key]; - if (differs(newValue, oldValue)) { - var callbacks = group[key]; - if (!callbacks) continue; + var callbacks = group[key]; + if (!callbacks) continue; - for (var i = 0; i < callbacks.length; i += 1) { - var callback = callbacks[i]; - if (callback.__calling) continue; + for (var i = 0; i < callbacks.length; i += 1) { + var callback = callbacks[i]; + if (callback.__calling) continue; - callback.__calling = true; - callback.call(component, newValue, oldValue); - callback.__calling = false; - } + callback.__calling = true; + callback.call(component, newValue, oldValue); + callback.__calling = false; } } } @@ -130,6 +128,23 @@ function set(newState) { this._root._lock = false; } +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign({}, oldState, newState); + this._recompute(changed, this._state, oldState, false); + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.update(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); +} + function callAll(fns) { while (fns && fns.length) fns.pop()(); } @@ -141,7 +156,9 @@ var proto = { observe: observe, on: on, set: set, - teardown: destroy + teardown: destroy, + _recompute: noop, + _set: _set }; var template = (function () { @@ -181,6 +198,8 @@ function create_main_fragment ( state, component ) { appendNode( text, button ); }, + update: noop, + unmount: function () { detachNode( button ); }, @@ -215,11 +234,4 @@ function SvelteComponent ( options ) { assign( SvelteComponent.prototype, template.methods, proto ); -SvelteComponent.prototype._set = function _set ( newState ) { - var oldState = this._state; - this._state = assign( {}, oldState, newState ); - dispatchObservers( this, this._observers.pre, newState, oldState ); - dispatchObservers( this, this._observers.post, newState, oldState ); -}; - export default SvelteComponent; diff --git a/test/js/samples/event-handlers-custom/expected.js b/test/js/samples/event-handlers-custom/expected.js index 9d5e771bdd..54e9111aff 100644 --- a/test/js/samples/event-handlers-custom/expected.js +++ b/test/js/samples/event-handlers-custom/expected.js @@ -1,4 +1,4 @@ -import { appendNode, assign, createElement, createText, detachNode, dispatchObservers, insertNode, proto } from "svelte/shared.js"; +import { appendNode, assign, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; var template = (function () { return { @@ -37,6 +37,8 @@ function create_main_fragment ( state, component ) { appendNode( text, button ); }, + update: noop, + unmount: function () { detachNode( button ); }, @@ -71,11 +73,4 @@ function SvelteComponent ( options ) { assign( SvelteComponent.prototype, template.methods, proto ); -SvelteComponent.prototype._set = function _set ( newState ) { - var oldState = this._state; - this._state = assign( {}, oldState, newState ); - dispatchObservers( this, this._observers.pre, newState, oldState ); - dispatchObservers( this, this._observers.post, newState, oldState ); -}; - export default SvelteComponent; \ No newline at end of file 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 273ce81fc1..f3f7a371be 100644 --- a/test/js/samples/if-block-no-update/expected-bundle.js +++ b/test/js/samples/if-block-no-update/expected-bundle.js @@ -52,25 +52,23 @@ function differs(a, b) { return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -function dispatchObservers(component, group, newState, oldState) { +function dispatchObservers(component, group, changed, newState, oldState) { for (var key in group) { - if (!(key in newState)) continue; + if (!(key in changed)) continue; var newValue = newState[key]; var oldValue = oldState[key]; - if (differs(newValue, oldValue)) { - var callbacks = group[key]; - if (!callbacks) continue; + var callbacks = group[key]; + if (!callbacks) continue; - for (var i = 0; i < callbacks.length; i += 1) { - var callback = callbacks[i]; - if (callback.__calling) continue; + for (var i = 0; i < callbacks.length; i += 1) { + var callback = callbacks[i]; + if (callback.__calling) continue; - callback.__calling = true; - callback.call(component, newValue, oldValue); - callback.__calling = false; - } + callback.__calling = true; + callback.call(component, newValue, oldValue); + callback.__calling = false; } } } @@ -134,6 +132,23 @@ function set(newState) { this._root._lock = false; } +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign({}, oldState, newState); + this._recompute(changed, this._state, oldState, false); + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.update(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); +} + function callAll(fns) { while (fns && fns.length) fns.pop()(); } @@ -145,7 +160,9 @@ var proto = { observe: observe, on: on, set: set, - teardown: destroy + teardown: destroy, + _recompute: noop, + _set: _set }; function create_main_fragment ( state, component ) { @@ -259,12 +276,4 @@ function SvelteComponent ( options ) { assign( SvelteComponent.prototype, proto ); -SvelteComponent.prototype._set = function _set ( newState ) { - var oldState = this._state; - this._state = assign( {}, oldState, newState ); - dispatchObservers( this, this._observers.pre, newState, oldState ); - this._fragment.update( newState, this._state ); - dispatchObservers( this, this._observers.post, newState, oldState ); -}; - export default SvelteComponent; diff --git a/test/js/samples/if-block-no-update/expected.js b/test/js/samples/if-block-no-update/expected.js index 8d30b66a03..025e0a0e43 100644 --- a/test/js/samples/if-block-no-update/expected.js +++ b/test/js/samples/if-block-no-update/expected.js @@ -1,4 +1,4 @@ -import { appendNode, assign, createComment, createElement, createText, detachNode, dispatchObservers, insertNode, noop, proto } from "svelte/shared.js"; +import { appendNode, assign, createComment, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment ( state, component ) { var if_block_anchor; @@ -111,12 +111,4 @@ function SvelteComponent ( options ) { assign( SvelteComponent.prototype, proto ); -SvelteComponent.prototype._set = function _set ( newState ) { - var oldState = this._state; - this._state = assign( {}, oldState, newState ); - dispatchObservers( this, this._observers.pre, newState, oldState ); - this._fragment.update( newState, this._state ); - dispatchObservers( this, this._observers.post, newState, oldState ); -}; - export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/if-block-simple/expected-bundle.js b/test/js/samples/if-block-simple/expected-bundle.js index 3b57117283..1ffa205c9c 100644 --- a/test/js/samples/if-block-simple/expected-bundle.js +++ b/test/js/samples/if-block-simple/expected-bundle.js @@ -52,25 +52,23 @@ function differs(a, b) { return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -function dispatchObservers(component, group, newState, oldState) { +function dispatchObservers(component, group, changed, newState, oldState) { for (var key in group) { - if (!(key in newState)) continue; + if (!(key in changed)) continue; var newValue = newState[key]; var oldValue = oldState[key]; - if (differs(newValue, oldValue)) { - var callbacks = group[key]; - if (!callbacks) continue; + var callbacks = group[key]; + if (!callbacks) continue; - for (var i = 0; i < callbacks.length; i += 1) { - var callback = callbacks[i]; - if (callback.__calling) continue; + for (var i = 0; i < callbacks.length; i += 1) { + var callback = callbacks[i]; + if (callback.__calling) continue; - callback.__calling = true; - callback.call(component, newValue, oldValue); - callback.__calling = false; - } + callback.__calling = true; + callback.call(component, newValue, oldValue); + callback.__calling = false; } } } @@ -134,6 +132,23 @@ function set(newState) { this._root._lock = false; } +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign({}, oldState, newState); + this._recompute(changed, this._state, oldState, false); + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.update(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); +} + function callAll(fns) { while (fns && fns.length) fns.pop()(); } @@ -145,7 +160,9 @@ var proto = { observe: observe, on: on, set: set, - teardown: destroy + teardown: destroy, + _recompute: noop, + _set: _set }; function create_main_fragment ( state, component ) { @@ -235,12 +252,4 @@ function SvelteComponent ( options ) { assign( SvelteComponent.prototype, proto ); -SvelteComponent.prototype._set = function _set ( newState ) { - var oldState = this._state; - this._state = assign( {}, oldState, newState ); - dispatchObservers( this, this._observers.pre, newState, oldState ); - this._fragment.update( newState, this._state ); - dispatchObservers( this, this._observers.post, newState, oldState ); -}; - export default SvelteComponent; diff --git a/test/js/samples/if-block-simple/expected.js b/test/js/samples/if-block-simple/expected.js index db04589093..2cc3be36f9 100644 --- a/test/js/samples/if-block-simple/expected.js +++ b/test/js/samples/if-block-simple/expected.js @@ -1,4 +1,4 @@ -import { appendNode, assign, createComment, createElement, createText, detachNode, dispatchObservers, insertNode, noop, proto } from "svelte/shared.js"; +import { appendNode, assign, createComment, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment ( state, component ) { var if_block_anchor; @@ -87,12 +87,4 @@ function SvelteComponent ( options ) { assign( SvelteComponent.prototype, proto ); -SvelteComponent.prototype._set = function _set ( newState ) { - var oldState = this._state; - this._state = assign( {}, oldState, newState ); - dispatchObservers( this, this._observers.pre, newState, oldState ); - this._fragment.update( newState, this._state ); - dispatchObservers( this, this._observers.post, newState, oldState ); -}; - export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/non-imported-component/expected-bundle.js b/test/js/samples/non-imported-component/expected-bundle.js index b40f56d109..98c6b12764 100644 --- a/test/js/samples/non-imported-component/expected-bundle.js +++ b/test/js/samples/non-imported-component/expected-bundle.js @@ -42,25 +42,23 @@ function differs(a, b) { return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -function dispatchObservers(component, group, newState, oldState) { +function dispatchObservers(component, group, changed, newState, oldState) { for (var key in group) { - if (!(key in newState)) continue; + if (!(key in changed)) continue; var newValue = newState[key]; var oldValue = oldState[key]; - if (differs(newValue, oldValue)) { - var callbacks = group[key]; - if (!callbacks) continue; + var callbacks = group[key]; + if (!callbacks) continue; - for (var i = 0; i < callbacks.length; i += 1) { - var callback = callbacks[i]; - if (callback.__calling) continue; + for (var i = 0; i < callbacks.length; i += 1) { + var callback = callbacks[i]; + if (callback.__calling) continue; - callback.__calling = true; - callback.call(component, newValue, oldValue); - callback.__calling = false; - } + callback.__calling = true; + callback.call(component, newValue, oldValue); + callback.__calling = false; } } } @@ -124,6 +122,23 @@ function set(newState) { this._root._lock = false; } +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign({}, oldState, newState); + this._recompute(changed, this._state, oldState, false); + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.update(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); +} + function callAll(fns) { while (fns && fns.length) fns.pop()(); } @@ -135,7 +150,9 @@ var proto = { observe: observe, on: on, set: set, - teardown: destroy + teardown: destroy, + _recompute: noop, + _set: _set }; var template = (function () { @@ -170,6 +187,8 @@ function create_main_fragment ( state, component ) { nonimported._fragment.mount( target, anchor ); }, + update: noop, + unmount: function () { imported._fragment.unmount(); detachNode( text ); @@ -221,11 +240,4 @@ function SvelteComponent ( options ) { assign( SvelteComponent.prototype, proto ); -SvelteComponent.prototype._set = function _set ( newState ) { - var oldState = this._state; - this._state = assign( {}, oldState, newState ); - dispatchObservers( this, this._observers.pre, newState, oldState ); - dispatchObservers( this, this._observers.post, newState, oldState ); -}; - export default SvelteComponent; diff --git a/test/js/samples/non-imported-component/expected.js b/test/js/samples/non-imported-component/expected.js index 2382e04ab3..ce86538e00 100644 --- a/test/js/samples/non-imported-component/expected.js +++ b/test/js/samples/non-imported-component/expected.js @@ -1,6 +1,6 @@ import Imported from 'Imported.html'; -import { assign, callAll, createText, detachNode, dispatchObservers, insertNode, proto } from "svelte/shared.js"; +import { assign, callAll, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; var template = (function () { return { @@ -34,6 +34,8 @@ function create_main_fragment ( state, component ) { nonimported._fragment.mount( target, anchor ); }, + update: noop, + unmount: function () { imported._fragment.unmount(); detachNode( text ); @@ -85,11 +87,4 @@ function SvelteComponent ( options ) { assign( SvelteComponent.prototype, proto ); -SvelteComponent.prototype._set = function _set ( newState ) { - var oldState = this._state; - this._state = assign( {}, oldState, newState ); - dispatchObservers( this, this._observers.pre, newState, oldState ); - dispatchObservers( this, this._observers.post, newState, oldState ); -}; - export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js index a754118158..f06892cbfb 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js @@ -28,25 +28,23 @@ function differs(a, b) { return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -function dispatchObservers(component, group, newState, oldState) { +function dispatchObservers(component, group, changed, newState, oldState) { for (var key in group) { - if (!(key in newState)) continue; + if (!(key in changed)) continue; var newValue = newState[key]; var oldValue = oldState[key]; - if (differs(newValue, oldValue)) { - var callbacks = group[key]; - if (!callbacks) continue; + var callbacks = group[key]; + if (!callbacks) continue; - for (var i = 0; i < callbacks.length; i += 1) { - var callback = callbacks[i]; - if (callback.__calling) continue; + for (var i = 0; i < callbacks.length; i += 1) { + var callback = callbacks[i]; + if (callback.__calling) continue; - callback.__calling = true; - callback.call(component, newValue, oldValue); - callback.__calling = false; - } + callback.__calling = true; + callback.call(component, newValue, oldValue); + callback.__calling = false; } } } @@ -110,6 +108,23 @@ function set(newState) { this._root._lock = false; } +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign({}, oldState, newState); + this._recompute(changed, this._state, oldState, false); + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.update(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); +} + function callAll(fns) { while (fns && fns.length) fns.pop()(); } @@ -121,7 +136,9 @@ var proto = { observe: observe, on: on, set: set, - teardown: destroy + teardown: destroy, + _recompute: noop, + _set: _set }; var template = (function () { @@ -139,6 +156,8 @@ function create_main_fragment ( state, component ) { mount: noop, + update: noop, + unmount: noop, destroy: noop @@ -182,11 +201,4 @@ function SvelteComponent ( options ) { assign( SvelteComponent.prototype, proto ); -SvelteComponent.prototype._set = function _set ( newState ) { - var oldState = this._state; - this._state = assign( {}, oldState, newState ); - dispatchObservers( this, this._observers.pre, newState, oldState ); - dispatchObservers( this, this._observers.post, newState, oldState ); -}; - export default SvelteComponent; diff --git a/test/js/samples/onrender-onteardown-rewritten/expected.js b/test/js/samples/onrender-onteardown-rewritten/expected.js index bd473fc2d7..a5125745c6 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected.js @@ -1,4 +1,4 @@ -import { assign, callAll, dispatchObservers, noop, proto } from "svelte/shared.js"; +import { assign, callAll, noop, proto } from "svelte/shared.js"; var template = (function () { return { @@ -15,6 +15,8 @@ function create_main_fragment ( state, component ) { mount: noop, + update: noop, + unmount: noop, destroy: noop @@ -58,11 +60,4 @@ function SvelteComponent ( options ) { assign( SvelteComponent.prototype, proto ); -SvelteComponent.prototype._set = function _set ( newState ) { - var oldState = this._state; - this._state = assign( {}, oldState, newState ); - dispatchObservers( this, this._observers.pre, newState, oldState ); - dispatchObservers( this, this._observers.post, newState, oldState ); -}; - export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/setup-method/expected-bundle.js b/test/js/samples/setup-method/expected-bundle.js index 006152cea5..4421ec1f87 100644 --- a/test/js/samples/setup-method/expected-bundle.js +++ b/test/js/samples/setup-method/expected-bundle.js @@ -28,25 +28,23 @@ function differs(a, b) { return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -function dispatchObservers(component, group, newState, oldState) { +function dispatchObservers(component, group, changed, newState, oldState) { for (var key in group) { - if (!(key in newState)) continue; + if (!(key in changed)) continue; var newValue = newState[key]; var oldValue = oldState[key]; - if (differs(newValue, oldValue)) { - var callbacks = group[key]; - if (!callbacks) continue; + var callbacks = group[key]; + if (!callbacks) continue; - for (var i = 0; i < callbacks.length; i += 1) { - var callback = callbacks[i]; - if (callback.__calling) continue; + for (var i = 0; i < callbacks.length; i += 1) { + var callback = callbacks[i]; + if (callback.__calling) continue; - callback.__calling = true; - callback.call(component, newValue, oldValue); - callback.__calling = false; - } + callback.__calling = true; + callback.call(component, newValue, oldValue); + callback.__calling = false; } } } @@ -110,6 +108,23 @@ function set(newState) { this._root._lock = false; } +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign({}, oldState, newState); + this._recompute(changed, this._state, oldState, false); + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.update(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); +} + function callAll(fns) { while (fns && fns.length) fns.pop()(); } @@ -121,7 +136,9 @@ var proto = { observe: observe, on: on, set: set, - teardown: destroy + teardown: destroy, + _recompute: noop, + _set: _set }; var template = (function () { @@ -150,6 +167,8 @@ function create_main_fragment ( state, component ) { mount: noop, + update: noop, + unmount: noop, destroy: noop @@ -180,13 +199,6 @@ function SvelteComponent ( options ) { assign( SvelteComponent.prototype, template.methods, proto ); -SvelteComponent.prototype._set = function _set ( newState ) { - var oldState = this._state; - this._state = assign( {}, oldState, newState ); - dispatchObservers( this, this._observers.pre, newState, oldState ); - dispatchObservers( this, this._observers.post, newState, oldState ); -}; - template.setup( SvelteComponent ); export default SvelteComponent; diff --git a/test/js/samples/setup-method/expected.js b/test/js/samples/setup-method/expected.js index 85f0d5c393..bf9da033ad 100644 --- a/test/js/samples/setup-method/expected.js +++ b/test/js/samples/setup-method/expected.js @@ -1,4 +1,4 @@ -import { assign, dispatchObservers, noop, proto } from "svelte/shared.js"; +import { assign, noop, proto } from "svelte/shared.js"; var template = (function () { return { @@ -26,6 +26,8 @@ function create_main_fragment ( state, component ) { mount: noop, + update: noop, + unmount: noop, destroy: noop @@ -56,13 +58,6 @@ function SvelteComponent ( options ) { assign( SvelteComponent.prototype, template.methods, proto ); -SvelteComponent.prototype._set = function _set ( newState ) { - var oldState = this._state; - this._state = assign( {}, oldState, newState ); - dispatchObservers( this, this._observers.pre, newState, oldState ); - dispatchObservers( this, this._observers.post, newState, oldState ); -}; - template.setup( SvelteComponent ); export default SvelteComponent; \ No newline at end of file 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 502e08b22e..9b64cd8600 100644 --- a/test/js/samples/use-elements-as-anchors/expected-bundle.js +++ b/test/js/samples/use-elements-as-anchors/expected-bundle.js @@ -52,25 +52,23 @@ function differs(a, b) { return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -function dispatchObservers(component, group, newState, oldState) { +function dispatchObservers(component, group, changed, newState, oldState) { for (var key in group) { - if (!(key in newState)) continue; + if (!(key in changed)) continue; var newValue = newState[key]; var oldValue = oldState[key]; - if (differs(newValue, oldValue)) { - var callbacks = group[key]; - if (!callbacks) continue; + var callbacks = group[key]; + if (!callbacks) continue; - for (var i = 0; i < callbacks.length; i += 1) { - var callback = callbacks[i]; - if (callback.__calling) continue; + for (var i = 0; i < callbacks.length; i += 1) { + var callback = callbacks[i]; + if (callback.__calling) continue; - callback.__calling = true; - callback.call(component, newValue, oldValue); - callback.__calling = false; - } + callback.__calling = true; + callback.call(component, newValue, oldValue); + callback.__calling = false; } } } @@ -134,6 +132,23 @@ function set(newState) { this._root._lock = false; } +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign({}, oldState, newState); + this._recompute(changed, this._state, oldState, false); + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.update(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); +} + function callAll(fns) { while (fns && fns.length) fns.pop()(); } @@ -145,7 +160,9 @@ var proto = { observe: observe, on: on, set: set, - teardown: destroy + teardown: destroy, + _recompute: noop, + _set: _set }; function create_main_fragment ( state, component ) { @@ -419,12 +436,4 @@ function SvelteComponent ( options ) { assign( SvelteComponent.prototype, proto ); -SvelteComponent.prototype._set = function _set ( newState ) { - var oldState = this._state; - this._state = assign( {}, oldState, newState ); - dispatchObservers( this, this._observers.pre, newState, oldState ); - this._fragment.update( newState, this._state ); - dispatchObservers( this, this._observers.post, newState, oldState ); -}; - export default SvelteComponent; diff --git a/test/js/samples/use-elements-as-anchors/expected.js b/test/js/samples/use-elements-as-anchors/expected.js index 3ed3f1e7db..28f0a660d4 100644 --- a/test/js/samples/use-elements-as-anchors/expected.js +++ b/test/js/samples/use-elements-as-anchors/expected.js @@ -1,4 +1,4 @@ -import { appendNode, assign, createComment, createElement, createText, detachNode, dispatchObservers, insertNode, noop, proto } from "svelte/shared.js"; +import { appendNode, assign, createComment, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment ( state, component ) { var div, text, p, text_1, text_2, text_3, text_4, p_1, text_5, text_6, text_8, if_block_4_anchor; @@ -271,12 +271,4 @@ function SvelteComponent ( options ) { assign( SvelteComponent.prototype, proto ); -SvelteComponent.prototype._set = function _set ( newState ) { - var oldState = this._state; - this._state = assign( {}, oldState, newState ); - dispatchObservers( this, this._observers.pre, newState, oldState ); - this._fragment.update( newState, this._state ); - dispatchObservers( this, this._observers.post, newState, oldState ); -}; - export default SvelteComponent; \ No newline at end of file