diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts index e103f428cf..acf161642d 100644 --- a/src/generators/dom/index.ts +++ b/src/generators/dom/index.ts @@ -123,7 +123,7 @@ export default function dom( const condition = `${deps.map(dep => `changed.${dep}`).join(' || ')}`; - const statement = `if (@differs(state.${key}, (state.${key} = %computed-${key}(${deps + const statement = `if (this._differs(state.${key}, (state.${key} = %computed-${key}(${deps .map(dep => `state.${dep}`) .join(', ')})))) changed.${key} = true;`; @@ -208,6 +208,7 @@ export default function dom( ${options.dev && !generator.customElement && `if (!options || (!options.target && !options.root)) throw new Error("'target' is a required option");`} @init(this, options); + this._differs = @differs; ${templateProperties.store && `this.store = %store();`} ${generator.usesRefs && `this.refs = {};`} this._state = @assign(${initialState.join(', ')}); diff --git a/src/shared/index.js b/src/shared/index.js index ec8706be6d..0005569532 100644 --- a/src/shared/index.js +++ b/src/shared/index.js @@ -26,25 +26,11 @@ export function destroyDev(detach) { } export function differs(a, b) { - if (a == null || b == null) return a !== b; - if (a.constructor !== b.constructor) return true; - if (a.valueOf && b.valueOf) { - a = a.valueOf(); - b = b.valueOf(); - } - if (typeof a === 'number' && isNaN(a) && isNaN(b)) return false; - return a !== b || typeof a === 'object' || typeof a === 'function'; + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } export function differsImmutable(a, b) { - if (a == null || b == null) return a !== b; - if (a.constructor !== b.constructor) return true; - if (a.valueOf && b.valueOf) { - a = a.valueOf(); - b = b.valueOf(); - } - if (typeof a === 'number' && isNaN(a) && isNaN(b)) return false; - return a !== b; + return a != a ? b == b : a !== b; } export function dispatchObservers(component, group, changed, newState, oldState) { @@ -168,28 +154,7 @@ export function _set(newState) { 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); - if (this._bind) this._bind(changed, this._state); - - if (this._fragment) { - dispatchObservers(this, this._observers.pre, changed, this._state, oldState); - this._fragment.p(changed, this._state); - dispatchObservers(this, this._observers.post, changed, this._state, oldState); - } -} - -export function _setImmutable(newState) { - var oldState = this._state, - changed = {}, - dirty = false; - - for (var key in newState) { - if (differsImmutable(newState[key], oldState[key])) changed[key] = dirty = true; + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; } if (!dirty) return; 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 ffc75c872c..ba89e7777b 100644 --- a/test/js/samples/collapses-text-around-comments/expected-bundle.js +++ b/test/js/samples/collapses-text-around-comments/expected-bundle.js @@ -52,14 +52,7 @@ function destroy(detach) { } function differs(a, b) { - if (a == null || b == null) return a !== b; - if (a.constructor !== b.constructor) return true; - if (a.valueOf && b.valueOf) { - a = a.valueOf(); - b = b.valueOf(); - } - if (typeof a === 'number' && isNaN(a) && isNaN(b)) return false; - return a !== b || typeof a === 'object' || typeof a === 'function'; + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } function dispatchObservers(component, group, changed, newState, oldState) { @@ -158,7 +151,7 @@ function _set(newState) { dirty = false; for (var key in newState) { - if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; } if (!dirty) return; @@ -250,6 +243,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign(data(), options.data); if (!document.getElementById("svelte-2794052100-style")) add_css(); diff --git a/test/js/samples/collapses-text-around-comments/expected.js b/test/js/samples/collapses-text-around-comments/expected.js index aea4721e36..a76fb36edf 100644 --- a/test/js/samples/collapses-text-around-comments/expected.js +++ b/test/js/samples/collapses-text-around-comments/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { appendNode, assign, createElement, createText, detachNode, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; +import { appendNode, assign, createElement, createText, detachNode, differs, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; function data() { return { foo: 42 } @@ -51,6 +51,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign(data(), options.data); if (!document.getElementById("svelte-2794052100-style")) add_css(); diff --git a/test/js/samples/component-static/expected-bundle.js b/test/js/samples/component-static/expected-bundle.js index 970b8e139a..b28b38ddb6 100644 --- a/test/js/samples/component-static/expected-bundle.js +++ b/test/js/samples/component-static/expected-bundle.js @@ -28,14 +28,7 @@ function destroy(detach) { } function differs(a, b) { - if (a == null || b == null) return a !== b; - if (a.constructor !== b.constructor) return true; - if (a.valueOf && b.valueOf) { - a = a.valueOf(); - b = b.valueOf(); - } - if (typeof a === 'number' && isNaN(a) && isNaN(b)) return false; - return a !== b || typeof a === 'object' || typeof a === 'function'; + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } function dispatchObservers(component, group, changed, newState, oldState) { @@ -134,7 +127,7 @@ function _set(newState) { dirty = false; for (var key in newState) { - if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; } if (!dirty) return; @@ -208,6 +201,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); if (!options.root) { diff --git a/test/js/samples/component-static/expected.js b/test/js/samples/component-static/expected.js index d75cce1253..de06c6fb2d 100644 --- a/test/js/samples/component-static/expected.js +++ b/test/js/samples/component-static/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { assign, callAll, init, noop, proto } from "svelte/shared.js"; +import { assign, callAll, differs, init, noop, proto } from "svelte/shared.js"; var Nested = window.Nested; @@ -33,6 +33,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); if (!options.root) { diff --git a/test/js/samples/computed-collapsed-if-immutable/_config.js b/test/js/samples/computed-collapsed-if-immutable/_config.js new file mode 100644 index 0000000000..06713941e0 --- /dev/null +++ b/test/js/samples/computed-collapsed-if-immutable/_config.js @@ -0,0 +1,5 @@ +export default { + options: { + immutable: true + } +}; \ No newline at end of file diff --git a/test/js/samples/computed-collapsed-if-immutable/expected-bundle.js b/test/js/samples/computed-collapsed-if-immutable/expected-bundle.js new file mode 100644 index 0000000000..509aa9328f --- /dev/null +++ b/test/js/samples/computed-collapsed-if-immutable/expected-bundle.js @@ -0,0 +1,218 @@ +function noop() {} + +function assign(target) { + var k, + source, + i = 1, + len = arguments.length; + for (; i < len; i++) { + source = arguments[i]; + for (k in source) target[k] = source[k]; + } + + return target; +} + +function blankObject() { + return Object.create(null); +} + +function destroy(detach) { + this.destroy = noop; + this.fire('destroy'); + this.set = this.get = noop; + + if (detach !== false) this._fragment.u(); + this._fragment.d(); + this._fragment = this._state = null; +} + +function differsImmutable(a, b) { + return a != a ? b == b : a !== b; +} + +function dispatchObservers(component, group, changed, newState, oldState) { + for (var key in group) { + if (!changed[key]) continue; + + var newValue = newState[key]; + var oldValue = oldState[key]; + + var callbacks = group[key]; + if (!callbacks) 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; + } + } +} + +function fire(eventName, data) { + var handlers = + eventName in this._handlers && this._handlers[eventName].slice(); + if (!handlers) return; + + for (var i = 0; i < handlers.length; i += 1) { + handlers[i].call(this, data); + } +} + +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + component._bind = options._bind; + + component.options = options; + component.root = options.root || component; + component.store = component.root.store || options.store; +} + +function observe(key, callback, options) { + var group = options && options.defer + ? this._observers.post + : this._observers.pre; + + (group[key] || (group[key] = [])).push(callback); + + if (!options || options.init !== false) { + callback.__calling = true; + callback.call(this, this._state[key]); + callback.__calling = false; + } + + return { + cancel: function() { + var index = group[key].indexOf(callback); + if (~index) group[key].splice(index, 1); + } + }; +} + +function on(eventName, handler) { + if (eventName === 'teardown') return this.on('destroy', handler); + + var handlers = this._handlers[eventName] || (this._handlers[eventName] = []); + handlers.push(handler); + + return { + cancel: function() { + var index = handlers.indexOf(handler); + if (~index) handlers.splice(index, 1); + } + }; +} + +function set(newState) { + this._set(assign({}, newState)); + if (this.root._lock) return; + this.root._lock = true; + callAll(this.root._beforecreate); + callAll(this.root._oncreate); + callAll(this.root._aftercreate); + this.root._lock = false; +} + +function _set(newState) { + var oldState = this._state, + changed = {}, + dirty = false; + + for (var key in newState) { + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; + } + if (!dirty) return; + + this._state = assign({}, oldState, newState); + this._recompute(changed, this._state); + if (this._bind) this._bind(changed, this._state); + + if (this._fragment) { + dispatchObservers(this, this._observers.pre, changed, this._state, oldState); + this._fragment.p(changed, this._state); + dispatchObservers(this, this._observers.post, changed, this._state, oldState); + } +} + +function callAll(fns) { + while (fns && fns.length) fns.shift()(); +} + +function _mount(target, anchor) { + this._fragment.m(target, anchor); +} + +function _unmount() { + if (this._fragment) this._fragment.u(); +} + +var proto = { + destroy: destroy, + get: get, + fire: fire, + observe: observe, + on: on, + set: set, + teardown: destroy, + _recompute: noop, + _set: _set, + _mount: _mount, + _unmount: _unmount +}; + +/* generated by Svelte vX.Y.Z */ +function a(x) { + return x * 2; +} + +function b(x) { + return x * 3; +} + +function create_main_fragment(state, component) { + + return { + c: noop, + + m: noop, + + p: noop, + + u: noop, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._differs = differsImmutable; + this._state = assign({}, options.data); + this._recompute({ x: 1 }, this._state); + + this._fragment = create_main_fragment(this._state, this); + + if (options.target) { + this._fragment.c(); + this._fragment.m(options.target, options.anchor || null); + } +} + +assign(SvelteComponent.prototype, proto); + +SvelteComponent.prototype._recompute = function _recompute(changed, state) { + if (changed.x) { + if (this._differs(state.a, (state.a = a(state.x)))) changed.a = true; + if (this._differs(state.b, (state.b = b(state.x)))) changed.b = true; + } +}; + +export default SvelteComponent; diff --git a/test/js/samples/computed-collapsed-if-immutable/expected.js b/test/js/samples/computed-collapsed-if-immutable/expected.js new file mode 100644 index 0000000000..b5beba1695 --- /dev/null +++ b/test/js/samples/computed-collapsed-if-immutable/expected.js @@ -0,0 +1,49 @@ +/* generated by Svelte vX.Y.Z */ +import { assign, differsImmutable, init, noop, proto } from "svelte/shared.js"; + +function a(x) { + return x * 2; +} + +function b(x) { + return x * 3; +} + +function create_main_fragment(state, component) { + + return { + c: noop, + + m: noop, + + p: noop, + + u: noop, + + d: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._differs = differsImmutable; + this._state = assign({}, options.data); + this._recompute({ x: 1 }, this._state); + + this._fragment = create_main_fragment(this._state, this); + + if (options.target) { + this._fragment.c(); + this._fragment.m(options.target, options.anchor || null); + } +} + +assign(SvelteComponent.prototype, proto); + +SvelteComponent.prototype._recompute = function _recompute(changed, state) { + if (changed.x) { + if (this._differs(state.a, (state.a = a(state.x)))) changed.a = true; + if (this._differs(state.b, (state.b = b(state.x)))) changed.b = true; + } +} +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/computed-collapsed-if-immutable/input.html b/test/js/samples/computed-collapsed-if-immutable/input.html new file mode 100644 index 0000000000..a68513b860 --- /dev/null +++ b/test/js/samples/computed-collapsed-if-immutable/input.html @@ -0,0 +1,8 @@ + \ 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 e9285f3bc0..475b5d3491 100644 --- a/test/js/samples/computed-collapsed-if/expected-bundle.js +++ b/test/js/samples/computed-collapsed-if/expected-bundle.js @@ -28,14 +28,7 @@ function destroy(detach) { } function differs(a, b) { - if (a == null || b == null) return a !== b; - if (a.constructor !== b.constructor) return true; - if (a.valueOf && b.valueOf) { - a = a.valueOf(); - b = b.valueOf(); - } - if (typeof a === 'number' && isNaN(a) && isNaN(b)) return false; - return a !== b || typeof a === 'object' || typeof a === 'function'; + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } function dispatchObservers(component, group, changed, newState, oldState) { @@ -134,7 +127,7 @@ function _set(newState) { dirty = false; for (var key in newState) { - if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; } if (!dirty) return; @@ -201,6 +194,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._recompute({ x: 1 }, this._state); @@ -216,8 +210,8 @@ assign(SvelteComponent.prototype, proto); SvelteComponent.prototype._recompute = function _recompute(changed, state) { if (changed.x) { - if (differs(state.a, (state.a = a(state.x)))) changed.a = true; - if (differs(state.b, (state.b = b(state.x)))) changed.b = true; + if (this._differs(state.a, (state.a = a(state.x)))) changed.a = true; + if (this._differs(state.b, (state.b = 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 c2f5e3c2be..c0765a4115 100644 --- a/test/js/samples/computed-collapsed-if/expected.js +++ b/test/js/samples/computed-collapsed-if/expected.js @@ -26,6 +26,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._recompute({ x: 1 }, this._state); @@ -41,8 +42,8 @@ assign(SvelteComponent.prototype, proto); SvelteComponent.prototype._recompute = function _recompute(changed, state) { if (changed.x) { - if (differs(state.a, (state.a = a(state.x)))) changed.a = true; - if (differs(state.b, (state.b = b(state.x)))) changed.b = true; + if (this._differs(state.a, (state.a = a(state.x)))) changed.a = true; + if (this._differs(state.b, (state.b = b(state.x)))) 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 6ccc9200d5..cfed183001 100644 --- a/test/js/samples/css-media-query/expected-bundle.js +++ b/test/js/samples/css-media-query/expected-bundle.js @@ -48,14 +48,7 @@ function destroy(detach) { } function differs(a, b) { - if (a == null || b == null) return a !== b; - if (a.constructor !== b.constructor) return true; - if (a.valueOf && b.valueOf) { - a = a.valueOf(); - b = b.valueOf(); - } - if (typeof a === 'number' && isNaN(a) && isNaN(b)) return false; - return a !== b || typeof a === 'object' || typeof a === 'function'; + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } function dispatchObservers(component, group, changed, newState, oldState) { @@ -154,7 +147,7 @@ function _set(newState) { dirty = false; for (var key in newState) { - if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; } if (!dirty) return; @@ -236,6 +229,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); if (!document.getElementById("svelte-3905933315-style")) add_css(); diff --git a/test/js/samples/css-media-query/expected.js b/test/js/samples/css-media-query/expected.js index 37afa6b42a..61e78032e8 100644 --- a/test/js/samples/css-media-query/expected.js +++ b/test/js/samples/css-media-query/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { appendNode, assign, createElement, detachNode, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; +import { appendNode, assign, createElement, detachNode, differs, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; function encapsulateStyles(node) { setAttribute(node, "svelte-3905933315", ""); @@ -41,6 +41,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); if (!document.getElementById("svelte-3905933315-style")) add_css(); 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 4948afea4d..2684f5ddb7 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js @@ -40,14 +40,7 @@ function destroy(detach) { } function differs(a, b) { - if (a == null || b == null) return a !== b; - if (a.constructor !== b.constructor) return true; - if (a.valueOf && b.valueOf) { - a = a.valueOf(); - b = b.valueOf(); - } - if (typeof a === 'number' && isNaN(a) && isNaN(b)) return false; - return a !== b || typeof a === 'object' || typeof a === 'function'; + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } function dispatchObservers(component, group, changed, newState, oldState) { @@ -146,7 +139,7 @@ function _set(newState) { dirty = false; for (var key in newState) { - if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; } if (!dirty) return; @@ -216,6 +209,7 @@ class SvelteComponent extends HTMLElement { constructor(options = {}) { super(); init(this, options); + this._differs = differs; this._state = assign({}, options.data); this.attachShadow({ mode: 'open' }); diff --git a/test/js/samples/css-shadow-dom-keyframes/expected.js b/test/js/samples/css-shadow-dom-keyframes/expected.js index 496586e632..de4528ff0e 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { assign, createElement, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; +import { assign, createElement, detachNode, differs, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var div; @@ -29,6 +29,7 @@ class SvelteComponent extends HTMLElement { constructor(options = {}) { super(); init(this, options); + this._differs = differs; this._state = assign({}, options.data); this.attachShadow({ mode: 'open' }); diff --git a/test/js/samples/deconflict-globals/expected-bundle.js b/test/js/samples/deconflict-globals/expected-bundle.js index 6733b68767..b3e979c0e9 100644 --- a/test/js/samples/deconflict-globals/expected-bundle.js +++ b/test/js/samples/deconflict-globals/expected-bundle.js @@ -28,14 +28,7 @@ function destroy(detach) { } function differs(a, b) { - if (a == null || b == null) return a !== b; - if (a.constructor !== b.constructor) return true; - if (a.valueOf && b.valueOf) { - a = a.valueOf(); - b = b.valueOf(); - } - if (typeof a === 'number' && isNaN(a) && isNaN(b)) return false; - return a !== b || typeof a === 'object' || typeof a === 'function'; + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } function dispatchObservers(component, group, changed, newState, oldState) { @@ -134,7 +127,7 @@ function _set(newState) { dirty = false; for (var key in newState) { - if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; } if (!dirty) return; @@ -203,6 +196,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign(data_1(), options.data); var _oncreate = oncreate.bind(this); diff --git a/test/js/samples/deconflict-globals/expected.js b/test/js/samples/deconflict-globals/expected.js index 8730f4e3c3..95da7a1a0c 100644 --- a/test/js/samples/deconflict-globals/expected.js +++ b/test/js/samples/deconflict-globals/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { assign, callAll, init, noop, proto } from "svelte/shared.js"; +import { assign, callAll, differs, init, noop, proto } from "svelte/shared.js"; function data_1() { return { @@ -28,6 +28,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign(data_1(), options.data); var _oncreate = oncreate.bind(this); diff --git a/test/js/samples/do-use-dataset/expected-bundle.js b/test/js/samples/do-use-dataset/expected-bundle.js index 442afd002e..8974c8a808 100644 --- a/test/js/samples/do-use-dataset/expected-bundle.js +++ b/test/js/samples/do-use-dataset/expected-bundle.js @@ -44,14 +44,7 @@ function destroy(detach) { } function differs(a, b) { - if (a == null || b == null) return a !== b; - if (a.constructor !== b.constructor) return true; - if (a.valueOf && b.valueOf) { - a = a.valueOf(); - b = b.valueOf(); - } - if (typeof a === 'number' && isNaN(a) && isNaN(b)) return false; - return a !== b || typeof a === 'object' || typeof a === 'function'; + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } function dispatchObservers(component, group, changed, newState, oldState) { @@ -150,7 +143,7 @@ function _set(newState) { dirty = false; for (var key in newState) { - if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; } if (!dirty) return; @@ -232,6 +225,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/do-use-dataset/expected.js b/test/js/samples/do-use-dataset/expected.js index 1ae7417469..cbe6e9ac2b 100644 --- a/test/js/samples/do-use-dataset/expected.js +++ b/test/js/samples/do-use-dataset/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { assign, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; +import { assign, createElement, createText, detachNode, differs, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var div, text, div_1; @@ -41,6 +41,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/dont-use-dataset-in-legacy/expected-bundle.js b/test/js/samples/dont-use-dataset-in-legacy/expected-bundle.js index 3b5681f2ca..9f546da356 100644 --- a/test/js/samples/dont-use-dataset-in-legacy/expected-bundle.js +++ b/test/js/samples/dont-use-dataset-in-legacy/expected-bundle.js @@ -48,14 +48,7 @@ function destroy(detach) { } function differs(a, b) { - if (a == null || b == null) return a !== b; - if (a.constructor !== b.constructor) return true; - if (a.valueOf && b.valueOf) { - a = a.valueOf(); - b = b.valueOf(); - } - if (typeof a === 'number' && isNaN(a) && isNaN(b)) return false; - return a !== b || typeof a === 'object' || typeof a === 'function'; + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } function dispatchObservers(component, group, changed, newState, oldState) { @@ -154,7 +147,7 @@ function _set(newState) { dirty = false; for (var key in newState) { - if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; } if (!dirty) return; @@ -236,6 +229,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/dont-use-dataset-in-legacy/expected.js b/test/js/samples/dont-use-dataset-in-legacy/expected.js index 03eef26ced..989b1a47f8 100644 --- a/test/js/samples/dont-use-dataset-in-legacy/expected.js +++ b/test/js/samples/dont-use-dataset-in-legacy/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { assign, createElement, createText, detachNode, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; +import { assign, createElement, createText, detachNode, differs, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; function create_main_fragment(state, component) { var div, text, div_1; @@ -41,6 +41,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/dont-use-dataset-in-svg/expected-bundle.js b/test/js/samples/dont-use-dataset-in-svg/expected-bundle.js index 242ac51828..e6c5fee0c6 100644 --- a/test/js/samples/dont-use-dataset-in-svg/expected-bundle.js +++ b/test/js/samples/dont-use-dataset-in-svg/expected-bundle.js @@ -48,14 +48,7 @@ function destroy(detach) { } function differs(a, b) { - if (a == null || b == null) return a !== b; - if (a.constructor !== b.constructor) return true; - if (a.valueOf && b.valueOf) { - a = a.valueOf(); - b = b.valueOf(); - } - if (typeof a === 'number' && isNaN(a) && isNaN(b)) return false; - return a !== b || typeof a === 'object' || typeof a === 'function'; + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } function dispatchObservers(component, group, changed, newState, oldState) { @@ -154,7 +147,7 @@ function _set(newState) { dirty = false; for (var key in newState) { - if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; } if (!dirty) return; @@ -234,6 +227,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/dont-use-dataset-in-svg/expected.js b/test/js/samples/dont-use-dataset-in-svg/expected.js index b87f152298..f96da75975 100644 --- a/test/js/samples/dont-use-dataset-in-svg/expected.js +++ b/test/js/samples/dont-use-dataset-in-svg/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { appendNode, assign, createSvgElement, detachNode, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; +import { appendNode, assign, createSvgElement, detachNode, differs, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; function create_main_fragment(state, component) { var svg, g, g_1; @@ -39,6 +39,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); 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 ca09f3774f..428e9c739a 100644 --- a/test/js/samples/each-block-changed-check/expected-bundle.js +++ b/test/js/samples/each-block-changed-check/expected-bundle.js @@ -60,14 +60,7 @@ function destroy(detach) { } function differs(a, b) { - if (a == null || b == null) return a !== b; - if (a.constructor !== b.constructor) return true; - if (a.valueOf && b.valueOf) { - a = a.valueOf(); - b = b.valueOf(); - } - if (typeof a === 'number' && isNaN(a) && isNaN(b)) return false; - return a !== b || typeof a === 'object' || typeof a === 'function'; + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } function dispatchObservers(component, group, changed, newState, oldState) { @@ -166,7 +159,7 @@ function _set(newState) { dirty = false; for (var key in newState) { - if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; } if (!dirty) return; @@ -348,6 +341,7 @@ function create_each_block(state, comments, comment, i, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js index 29a57322e0..c436550f07 100644 --- a/test/js/samples/each-block-changed-check/expected.js +++ b/test/js/samples/each-block-changed-check/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { appendNode, assign, createElement, createText, destroyEach, detachAfter, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; +import { appendNode, assign, createElement, createText, destroyEach, detachAfter, detachNode, differs, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var text, p, text_1; @@ -141,6 +141,7 @@ function create_each_block(state, comments, comment, i, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/event-handlers-custom/expected-bundle.js b/test/js/samples/event-handlers-custom/expected-bundle.js index f9e32a0256..819b653caa 100644 --- a/test/js/samples/event-handlers-custom/expected-bundle.js +++ b/test/js/samples/event-handlers-custom/expected-bundle.js @@ -40,14 +40,7 @@ function destroy(detach) { } function differs(a, b) { - if (a == null || b == null) return a !== b; - if (a.constructor !== b.constructor) return true; - if (a.valueOf && b.valueOf) { - a = a.valueOf(); - b = b.valueOf(); - } - if (typeof a === 'number' && isNaN(a) && isNaN(b)) return false; - return a !== b || typeof a === 'object' || typeof a === 'function'; + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } function dispatchObservers(component, group, changed, newState, oldState) { @@ -146,7 +139,7 @@ function _set(newState) { dirty = false; for (var key in newState) { - if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; } if (!dirty) return; @@ -233,6 +226,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/event-handlers-custom/expected.js b/test/js/samples/event-handlers-custom/expected.js index f7862efb62..1d5ae4b17e 100644 --- a/test/js/samples/event-handlers-custom/expected.js +++ b/test/js/samples/event-handlers-custom/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { assign, createElement, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; +import { assign, createElement, detachNode, differs, init, insertNode, noop, proto } from "svelte/shared.js"; function foo( node, callback ) { // code goes here @@ -46,6 +46,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/head-no-whitespace/expected-bundle.js b/test/js/samples/head-no-whitespace/expected-bundle.js index 62aac217d5..398617dd13 100644 --- a/test/js/samples/head-no-whitespace/expected-bundle.js +++ b/test/js/samples/head-no-whitespace/expected-bundle.js @@ -40,14 +40,7 @@ function destroy(detach) { } function differs(a, b) { - if (a == null || b == null) return a !== b; - if (a.constructor !== b.constructor) return true; - if (a.valueOf && b.valueOf) { - a = a.valueOf(); - b = b.valueOf(); - } - if (typeof a === 'number' && isNaN(a) && isNaN(b)) return false; - return a !== b || typeof a === 'object' || typeof a === 'function'; + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } function dispatchObservers(component, group, changed, newState, oldState) { @@ -146,7 +139,7 @@ function _set(newState) { dirty = false; for (var key in newState) { - if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; } if (!dirty) return; @@ -223,6 +216,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/head-no-whitespace/expected.js b/test/js/samples/head-no-whitespace/expected.js index 32a1a5da88..d9bee61c62 100644 --- a/test/js/samples/head-no-whitespace/expected.js +++ b/test/js/samples/head-no-whitespace/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { appendNode, assign, createElement, detachNode, init, noop, proto } from "svelte/shared.js"; +import { appendNode, assign, createElement, detachNode, differs, init, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var meta, meta_1; @@ -36,6 +36,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); 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 681edc072e..b3dc0c6b13 100644 --- a/test/js/samples/if-block-no-update/expected-bundle.js +++ b/test/js/samples/if-block-no-update/expected-bundle.js @@ -44,14 +44,7 @@ function destroy(detach) { } function differs(a, b) { - if (a == null || b == null) return a !== b; - if (a.constructor !== b.constructor) return true; - if (a.valueOf && b.valueOf) { - a = a.valueOf(); - b = b.valueOf(); - } - if (typeof a === 'number' && isNaN(a) && isNaN(b)) return false; - return a !== b || typeof a === 'object' || typeof a === 'function'; + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } function dispatchObservers(component, group, changed, newState, oldState) { @@ -150,7 +143,7 @@ function _set(newState) { dirty = false; for (var key in newState) { - if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; } if (!dirty) return; @@ -281,6 +274,7 @@ function select_block_type(state) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/if-block-no-update/expected.js b/test/js/samples/if-block-no-update/expected.js index 8f030e4e53..59c54d1ad7 100644 --- a/test/js/samples/if-block-no-update/expected.js +++ b/test/js/samples/if-block-no-update/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { assign, createComment, createElement, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; +import { assign, createComment, createElement, detachNode, differs, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var if_block_anchor; @@ -90,6 +90,7 @@ function select_block_type(state) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/if-block-simple/expected-bundle.js b/test/js/samples/if-block-simple/expected-bundle.js index 9ce6331f44..9dac6d03a9 100644 --- a/test/js/samples/if-block-simple/expected-bundle.js +++ b/test/js/samples/if-block-simple/expected-bundle.js @@ -44,14 +44,7 @@ function destroy(detach) { } function differs(a, b) { - if (a == null || b == null) return a !== b; - if (a.constructor !== b.constructor) return true; - if (a.valueOf && b.valueOf) { - a = a.valueOf(); - b = b.valueOf(); - } - if (typeof a === 'number' && isNaN(a) && isNaN(b)) return false; - return a !== b || typeof a === 'object' || typeof a === 'function'; + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } function dispatchObservers(component, group, changed, newState, oldState) { @@ -150,7 +143,7 @@ function _set(newState) { dirty = false; for (var key in newState) { - if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; } if (!dirty) return; @@ -257,6 +250,7 @@ function create_if_block(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/if-block-simple/expected.js b/test/js/samples/if-block-simple/expected.js index 0b9fbece70..667640451f 100644 --- a/test/js/samples/if-block-simple/expected.js +++ b/test/js/samples/if-block-simple/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { assign, createComment, createElement, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; +import { assign, createComment, createElement, detachNode, differs, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var if_block_anchor; @@ -66,6 +66,7 @@ function create_if_block(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); 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 9077eea9d7..8843db047b 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-multiple/expected-bundle.js @@ -44,14 +44,7 @@ function destroy(detach) { } function differs(a, b) { - if (a == null || b == null) return a !== b; - if (a.constructor !== b.constructor) return true; - if (a.valueOf && b.valueOf) { - a = a.valueOf(); - b = b.valueOf(); - } - if (typeof a === 'number' && isNaN(a) && isNaN(b)) return false; - return a !== b || typeof a === 'object' || typeof a === 'function'; + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } function dispatchObservers(component, group, changed, newState, oldState) { @@ -150,7 +143,7 @@ function _set(newState) { dirty = false; for (var key in newState) { - if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; } if (!dirty) return; @@ -230,6 +223,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/inline-style-optimized-multiple/expected.js b/test/js/samples/inline-style-optimized-multiple/expected.js index 77173460e2..0b0aca132b 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected.js +++ b/test/js/samples/inline-style-optimized-multiple/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; +import { assign, createElement, detachNode, differs, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; function create_main_fragment(state, component) { var div; @@ -39,6 +39,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); 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 7277ff587a..e88379a4e4 100644 --- a/test/js/samples/inline-style-optimized-url/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-url/expected-bundle.js @@ -44,14 +44,7 @@ function destroy(detach) { } function differs(a, b) { - if (a == null || b == null) return a !== b; - if (a.constructor !== b.constructor) return true; - if (a.valueOf && b.valueOf) { - a = a.valueOf(); - b = b.valueOf(); - } - if (typeof a === 'number' && isNaN(a) && isNaN(b)) return false; - return a !== b || typeof a === 'object' || typeof a === 'function'; + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } function dispatchObservers(component, group, changed, newState, oldState) { @@ -150,7 +143,7 @@ function _set(newState) { dirty = false; for (var key in newState) { - if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; } if (!dirty) return; @@ -225,6 +218,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/inline-style-optimized-url/expected.js b/test/js/samples/inline-style-optimized-url/expected.js index bed00356f6..1d8d5c467a 100644 --- a/test/js/samples/inline-style-optimized-url/expected.js +++ b/test/js/samples/inline-style-optimized-url/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; +import { assign, createElement, detachNode, differs, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; function create_main_fragment(state, component) { var div; @@ -34,6 +34,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/inline-style-optimized/expected-bundle.js b/test/js/samples/inline-style-optimized/expected-bundle.js index 9b3f41768f..a1b8278e87 100644 --- a/test/js/samples/inline-style-optimized/expected-bundle.js +++ b/test/js/samples/inline-style-optimized/expected-bundle.js @@ -44,14 +44,7 @@ function destroy(detach) { } function differs(a, b) { - if (a == null || b == null) return a !== b; - if (a.constructor !== b.constructor) return true; - if (a.valueOf && b.valueOf) { - a = a.valueOf(); - b = b.valueOf(); - } - if (typeof a === 'number' && isNaN(a) && isNaN(b)) return false; - return a !== b || typeof a === 'object' || typeof a === 'function'; + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } function dispatchObservers(component, group, changed, newState, oldState) { @@ -150,7 +143,7 @@ function _set(newState) { dirty = false; for (var key in newState) { - if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; } if (!dirty) return; @@ -225,6 +218,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/inline-style-optimized/expected.js b/test/js/samples/inline-style-optimized/expected.js index 7f873e296c..7f4f19248b 100644 --- a/test/js/samples/inline-style-optimized/expected.js +++ b/test/js/samples/inline-style-optimized/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; +import { assign, createElement, detachNode, differs, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; function create_main_fragment(state, component) { var div; @@ -34,6 +34,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/inline-style-unoptimized/expected-bundle.js b/test/js/samples/inline-style-unoptimized/expected-bundle.js index f1a5a53d7f..9db0da26fe 100644 --- a/test/js/samples/inline-style-unoptimized/expected-bundle.js +++ b/test/js/samples/inline-style-unoptimized/expected-bundle.js @@ -44,14 +44,7 @@ function destroy(detach) { } function differs(a, b) { - if (a == null || b == null) return a !== b; - if (a.constructor !== b.constructor) return true; - if (a.valueOf && b.valueOf) { - a = a.valueOf(); - b = b.valueOf(); - } - if (typeof a === 'number' && isNaN(a) && isNaN(b)) return false; - return a !== b || typeof a === 'object' || typeof a === 'function'; + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } function dispatchObservers(component, group, changed, newState, oldState) { @@ -150,7 +143,7 @@ function _set(newState) { dirty = false; for (var key in newState) { - if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; } if (!dirty) return; @@ -236,6 +229,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/inline-style-unoptimized/expected.js b/test/js/samples/inline-style-unoptimized/expected.js index 4c4d38d2bf..0e53480fe8 100644 --- a/test/js/samples/inline-style-unoptimized/expected.js +++ b/test/js/samples/inline-style-unoptimized/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { assign, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; +import { assign, createElement, createText, detachNode, differs, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var div, text, div_1, div_1_style_value; @@ -45,6 +45,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); 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 b32377763e..fb3f125b00 100644 --- a/test/js/samples/input-without-blowback-guard/expected-bundle.js +++ b/test/js/samples/input-without-blowback-guard/expected-bundle.js @@ -48,14 +48,7 @@ function destroy(detach) { } function differs(a, b) { - if (a == null || b == null) return a !== b; - if (a.constructor !== b.constructor) return true; - if (a.valueOf && b.valueOf) { - a = a.valueOf(); - b = b.valueOf(); - } - if (typeof a === 'number' && isNaN(a) && isNaN(b)) return false; - return a !== b || typeof a === 'object' || typeof a === 'function'; + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } function dispatchObservers(component, group, changed, newState, oldState) { @@ -154,7 +147,7 @@ function _set(newState) { dirty = false; for (var key in newState) { - if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; } if (!dirty) return; @@ -236,6 +229,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/input-without-blowback-guard/expected.js b/test/js/samples/input-without-blowback-guard/expected.js index 03f27ab6d9..9342b25ec9 100644 --- a/test/js/samples/input-without-blowback-guard/expected.js +++ b/test/js/samples/input-without-blowback-guard/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { addListener, assign, createElement, detachNode, init, insertNode, proto, removeListener } from "svelte/shared.js"; +import { addListener, assign, createElement, detachNode, differs, init, insertNode, proto, removeListener } from "svelte/shared.js"; function create_main_fragment(state, component) { var input; @@ -41,6 +41,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/legacy-input-type/expected-bundle.js b/test/js/samples/legacy-input-type/expected-bundle.js index 1dbd32f619..8b6e2faa8f 100644 --- a/test/js/samples/legacy-input-type/expected-bundle.js +++ b/test/js/samples/legacy-input-type/expected-bundle.js @@ -46,14 +46,7 @@ function destroy(detach) { } function differs(a, b) { - if (a == null || b == null) return a !== b; - if (a.constructor !== b.constructor) return true; - if (a.valueOf && b.valueOf) { - a = a.valueOf(); - b = b.valueOf(); - } - if (typeof a === 'number' && isNaN(a) && isNaN(b)) return false; - return a !== b || typeof a === 'object' || typeof a === 'function'; + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } function dispatchObservers(component, group, changed, newState, oldState) { @@ -152,7 +145,7 @@ function _set(newState) { dirty = false; for (var key in newState) { - if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; } if (!dirty) return; @@ -223,6 +216,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/legacy-input-type/expected.js b/test/js/samples/legacy-input-type/expected.js index 719f550044..22d71f036d 100644 --- a/test/js/samples/legacy-input-type/expected.js +++ b/test/js/samples/legacy-input-type/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { assign, createElement, detachNode, init, insertNode, noop, proto, setInputType } from "svelte/shared.js"; +import { assign, createElement, detachNode, differs, init, insertNode, noop, proto, setInputType } from "svelte/shared.js"; function create_main_fragment(state, component) { var input; @@ -30,6 +30,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/legacy-quote-class/expected-bundle.js b/test/js/samples/legacy-quote-class/expected-bundle.js index 0b203fb4b6..b4900a16b5 100644 --- a/test/js/samples/legacy-quote-class/expected-bundle.js +++ b/test/js/samples/legacy-quote-class/expected-bundle.js @@ -63,14 +63,7 @@ function destroy(detach) { } function differs(a, b) { - if (a == null || b == null) return a !== b; - if (a.constructor !== b.constructor) return true; - if (a.valueOf && b.valueOf) { - a = a.valueOf(); - b = b.valueOf(); - } - if (typeof a === 'number' && isNaN(a) && isNaN(b)) return false; - return a !== b || typeof a === 'object' || typeof a === 'function'; + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } function dispatchObservers(component, group, changed, newState, oldState) { @@ -169,7 +162,7 @@ function _set(newState) { dirty = false; for (var key in newState) { - if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; } if (!dirty) return; @@ -248,6 +241,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/legacy-quote-class/expected.js b/test/js/samples/legacy-quote-class/expected.js index 0b49103c47..c4421f91cd 100644 --- a/test/js/samples/legacy-quote-class/expected.js +++ b/test/js/samples/legacy-quote-class/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { assign, children, claimElement, createElement, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; +import { assign, children, claimElement, createElement, detachNode, differs, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var div; @@ -38,6 +38,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/media-bindings/expected-bundle.js b/test/js/samples/media-bindings/expected-bundle.js index ec971167be..2eacb53f8c 100644 --- a/test/js/samples/media-bindings/expected-bundle.js +++ b/test/js/samples/media-bindings/expected-bundle.js @@ -56,14 +56,7 @@ function destroy(detach) { } function differs(a, b) { - if (a == null || b == null) return a !== b; - if (a.constructor !== b.constructor) return true; - if (a.valueOf && b.valueOf) { - a = a.valueOf(); - b = b.valueOf(); - } - if (typeof a === 'number' && isNaN(a) && isNaN(b)) return false; - return a !== b || typeof a === 'object' || typeof a === 'function'; + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } function dispatchObservers(component, group, changed, newState, oldState) { @@ -162,7 +155,7 @@ function _set(newState) { dirty = false; for (var key in newState) { - if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; } if (!dirty) return; @@ -289,6 +282,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); if (!options.root) { diff --git a/test/js/samples/media-bindings/expected.js b/test/js/samples/media-bindings/expected.js index ae80f288f6..503228ce06 100644 --- a/test/js/samples/media-bindings/expected.js +++ b/test/js/samples/media-bindings/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { addListener, assign, callAll, createElement, detachNode, init, insertNode, proto, removeListener, timeRangesToArray } from "svelte/shared.js"; +import { addListener, assign, callAll, createElement, detachNode, differs, init, insertNode, proto, removeListener, timeRangesToArray } from "svelte/shared.js"; function create_main_fragment(state, component) { var audio, audio_is_paused = true, audio_updating = false, audio_animationframe; @@ -86,6 +86,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); if (!options.root) { diff --git a/test/js/samples/non-imported-component/expected-bundle.js b/test/js/samples/non-imported-component/expected-bundle.js index 46de1d757e..9cba5b8bfb 100644 --- a/test/js/samples/non-imported-component/expected-bundle.js +++ b/test/js/samples/non-imported-component/expected-bundle.js @@ -42,14 +42,7 @@ function destroy(detach) { } function differs(a, b) { - if (a == null || b == null) return a !== b; - if (a.constructor !== b.constructor) return true; - if (a.valueOf && b.valueOf) { - a = a.valueOf(); - b = b.valueOf(); - } - if (typeof a === 'number' && isNaN(a) && isNaN(b)) return false; - return a !== b || typeof a === 'object' || typeof a === 'function'; + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } function dispatchObservers(component, group, changed, newState, oldState) { @@ -148,7 +141,7 @@ function _set(newState) { dirty = false; for (var key in newState) { - if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; } if (!dirty) return; @@ -231,6 +224,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); if (!options.root) { diff --git a/test/js/samples/non-imported-component/expected.js b/test/js/samples/non-imported-component/expected.js index e7fc2c7255..c35b4f88a7 100644 --- a/test/js/samples/non-imported-component/expected.js +++ b/test/js/samples/non-imported-component/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { assign, callAll, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; +import { assign, callAll, createText, detachNode, differs, init, insertNode, noop, proto } from "svelte/shared.js"; import Imported from 'Imported.html'; @@ -45,6 +45,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); if (!options.root) { diff --git a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js index b65e0bfc2a..26f52231fc 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js @@ -28,14 +28,7 @@ function destroy(detach) { } function differs(a, b) { - if (a == null || b == null) return a !== b; - if (a.constructor !== b.constructor) return true; - if (a.valueOf && b.valueOf) { - a = a.valueOf(); - b = b.valueOf(); - } - if (typeof a === 'number' && isNaN(a) && isNaN(b)) return false; - return a !== b || typeof a === 'object' || typeof a === 'function'; + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } function dispatchObservers(component, group, changed, newState, oldState) { @@ -134,7 +127,7 @@ function _set(newState) { dirty = false; for (var key in newState) { - if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; } if (!dirty) return; @@ -197,6 +190,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._handlers.destroy = [ondestroy]; diff --git a/test/js/samples/onrender-onteardown-rewritten/expected.js b/test/js/samples/onrender-onteardown-rewritten/expected.js index 51763c0b00..02203f83c0 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { assign, callAll, init, noop, proto } from "svelte/shared.js"; +import { assign, callAll, differs, init, noop, proto } from "svelte/shared.js"; function oncreate() {}; @@ -22,6 +22,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._handlers.destroy = [ondestroy]; diff --git a/test/js/samples/setup-method/expected-bundle.js b/test/js/samples/setup-method/expected-bundle.js index 80bb847692..103bf174ac 100644 --- a/test/js/samples/setup-method/expected-bundle.js +++ b/test/js/samples/setup-method/expected-bundle.js @@ -28,14 +28,7 @@ function destroy(detach) { } function differs(a, b) { - if (a == null || b == null) return a !== b; - if (a.constructor !== b.constructor) return true; - if (a.valueOf && b.valueOf) { - a = a.valueOf(); - b = b.valueOf(); - } - if (typeof a === 'number' && isNaN(a) && isNaN(b)) return false; - return a !== b || typeof a === 'object' || typeof a === 'function'; + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } function dispatchObservers(component, group, changed, newState, oldState) { @@ -134,7 +127,7 @@ function _set(newState) { dirty = false; for (var key in newState) { - if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; } if (!dirty) return; @@ -209,6 +202,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/setup-method/expected.js b/test/js/samples/setup-method/expected.js index 092a32ed3b..5b306a12e7 100644 --- a/test/js/samples/setup-method/expected.js +++ b/test/js/samples/setup-method/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { assign, init, noop, proto } from "svelte/shared.js"; +import { assign, differs, init, noop, proto } from "svelte/shared.js"; var methods = { foo ( bar ) { @@ -34,6 +34,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/svg-title/expected-bundle.js b/test/js/samples/svg-title/expected-bundle.js index 1ee4d64a48..2050f6dcfe 100644 --- a/test/js/samples/svg-title/expected-bundle.js +++ b/test/js/samples/svg-title/expected-bundle.js @@ -48,14 +48,7 @@ function destroy(detach) { } function differs(a, b) { - if (a == null || b == null) return a !== b; - if (a.constructor !== b.constructor) return true; - if (a.valueOf && b.valueOf) { - a = a.valueOf(); - b = b.valueOf(); - } - if (typeof a === 'number' && isNaN(a) && isNaN(b)) return false; - return a !== b || typeof a === 'object' || typeof a === 'function'; + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } function dispatchObservers(component, group, changed, newState, oldState) { @@ -154,7 +147,7 @@ function _set(newState) { dirty = false; for (var key in newState) { - if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; } if (!dirty) return; @@ -224,6 +217,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/svg-title/expected.js b/test/js/samples/svg-title/expected.js index 39ccf227c0..6c5d08ca00 100644 --- a/test/js/samples/svg-title/expected.js +++ b/test/js/samples/svg-title/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { appendNode, assign, createSvgElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; +import { appendNode, assign, createSvgElement, createText, detachNode, differs, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var svg, title, text; @@ -29,6 +29,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/title/expected-bundle.js b/test/js/samples/title/expected-bundle.js index 454a1fad0e..2fcc0b6197 100644 --- a/test/js/samples/title/expected-bundle.js +++ b/test/js/samples/title/expected-bundle.js @@ -28,14 +28,7 @@ function destroy(detach) { } function differs(a, b) { - if (a == null || b == null) return a !== b; - if (a.constructor !== b.constructor) return true; - if (a.valueOf && b.valueOf) { - a = a.valueOf(); - b = b.valueOf(); - } - if (typeof a === 'number' && isNaN(a) && isNaN(b)) return false; - return a !== b || typeof a === 'object' || typeof a === 'function'; + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } function dispatchObservers(component, group, changed, newState, oldState) { @@ -134,7 +127,7 @@ function _set(newState) { dirty = false; for (var key in newState) { - if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; } if (!dirty) return; @@ -200,6 +193,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/title/expected.js b/test/js/samples/title/expected.js index 6aa903d25e..e15441fbdc 100644 --- a/test/js/samples/title/expected.js +++ b/test/js/samples/title/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { assign, init, noop, proto } from "svelte/shared.js"; +import { assign, differs, init, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var title_value; @@ -25,6 +25,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); 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 9ac57fe215..e22e431d53 100644 --- a/test/js/samples/use-elements-as-anchors/expected-bundle.js +++ b/test/js/samples/use-elements-as-anchors/expected-bundle.js @@ -52,14 +52,7 @@ function destroy(detach) { } function differs(a, b) { - if (a == null || b == null) return a !== b; - if (a.constructor !== b.constructor) return true; - if (a.valueOf && b.valueOf) { - a = a.valueOf(); - b = b.valueOf(); - } - if (typeof a === 'number' && isNaN(a) && isNaN(b)) return false; - return a !== b || typeof a === 'object' || typeof a === 'function'; + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } function dispatchObservers(component, group, changed, newState, oldState) { @@ -158,7 +151,7 @@ function _set(newState) { dirty = false; for (var key in newState) { - if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; } if (!dirty) return; @@ -447,6 +440,7 @@ function create_if_block_4(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/use-elements-as-anchors/expected.js b/test/js/samples/use-elements-as-anchors/expected.js index d2609c45b0..0b45ca8679 100644 --- a/test/js/samples/use-elements-as-anchors/expected.js +++ b/test/js/samples/use-elements-as-anchors/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { appendNode, assign, createComment, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; +import { appendNode, assign, createComment, createElement, createText, detachNode, differs, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var div, text, p, text_2, text_3, text_4, p_1, text_6, text_8, if_block_4_anchor; @@ -248,6 +248,7 @@ function create_if_block_4(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/window-binding-scroll/expected-bundle.js b/test/js/samples/window-binding-scroll/expected-bundle.js index 457f6d55ea..97231f4bb6 100644 --- a/test/js/samples/window-binding-scroll/expected-bundle.js +++ b/test/js/samples/window-binding-scroll/expected-bundle.js @@ -48,14 +48,7 @@ function destroy(detach) { } function differs(a, b) { - if (a == null || b == null) return a !== b; - if (a.constructor !== b.constructor) return true; - if (a.valueOf && b.valueOf) { - a = a.valueOf(); - b = b.valueOf(); - } - if (typeof a === 'number' && isNaN(a) && isNaN(b)) return false; - return a !== b || typeof a === 'object' || typeof a === 'function'; + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } function dispatchObservers(component, group, changed, newState, oldState) { @@ -154,7 +147,7 @@ function _set(newState) { dirty = false; for (var key in newState) { - if (differs(newState[key], oldState[key])) changed[key] = dirty = true; + if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true; } if (!dirty) return; @@ -248,6 +241,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._state.y = window.scrollY; diff --git a/test/js/samples/window-binding-scroll/expected.js b/test/js/samples/window-binding-scroll/expected.js index 70eae003d7..55bc0eb53a 100644 --- a/test/js/samples/window-binding-scroll/expected.js +++ b/test/js/samples/window-binding-scroll/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { appendNode, assign, createElement, createText, detachNode, init, insertNode, proto } from "svelte/shared.js"; +import { appendNode, assign, createElement, createText, detachNode, differs, init, insertNode, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var window_updating = false, clear_window_updating = function() { window_updating = false; }, window_updating_timeout, p, text, text_1; @@ -53,6 +53,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); + this._differs = differs; this._state = assign({}, options.data); this._state.y = window.scrollY; diff --git a/test/store/index.js b/test/store/index.js index d8053367a9..e3c024e4d5 100644 --- a/test/store/index.js +++ b/test/store/index.js @@ -187,4 +187,44 @@ describe('store', () => { }, /Cyclical dependency detected/); }); }); + + describe('immutable', () => { + it('observing state only changes on immutable updates', () => { + let newFoo; + let oldFoo; + let callCount = 0; + let value1 = {}; + let value2 = {}; + + const store = new Store({ + foo: value1 + }, { immutable: true }); + + store.observe('foo', (n, o) => { + callCount++; + newFoo = n; + oldFoo = o; + }); + + assert.equal(callCount, 1); + assert.equal(newFoo, value1); + assert.equal(oldFoo, undefined); + + store.set({ + foo: value1 + }); + + assert.equal(callCount, 1); + assert.equal(newFoo, value1); + assert.equal(oldFoo, undefined); + + store.set({ + foo: value2 + }); + + assert.equal(callCount, 2); + assert.equal(newFoo, value2); + assert.equal(oldFoo, value1); + }); + }); });