From d2f8e472a57da35202a1b0bff142641b2057a32f Mon Sep 17 00:00:00 2001 From: Jacob Wright Date: Thu, 8 Feb 2018 21:04:29 -0700 Subject: [PATCH 1/6] Add support to computed and store for immutable structures Adds optional performance support for apps using an immutable data structure such as redux. Adds the `immutable` boolean option for compile and an `immutable` option to store as well. When these options are used, computed will not recompute if the object has not changed. If your data structure is not immutable you should not use this as svelte cannot know if a mutation was made on objects. This PR also adds support for Dates and NaN values so computed properties will not recompute if a date has not changed or a value did not change from NaN. This closes out these issues: * https://github.com/sveltejs/svelte/issues/1146 * https://github.com/sveltejs/svelte/issues/1161 This is my first PR for Svelte. Any feedback would be appreciated! --- src/generators/dom/index.ts | 1 + src/interfaces.ts | 1 + src/shared/index.js | 41 ++++++++++++++++++- store.js | 8 ++-- .../expected-bundle.js | 9 +++- .../component-static/expected-bundle.js | 9 +++- .../computed-collapsed-if/expected-bundle.js | 9 +++- .../css-media-query/expected-bundle.js | 9 +++- .../expected-bundle.js | 9 +++- .../deconflict-globals/expected-bundle.js | 9 +++- .../samples/do-use-dataset/expected-bundle.js | 9 +++- .../expected-bundle.js | 9 +++- .../expected-bundle.js | 9 +++- .../expected-bundle.js | 9 +++- .../event-handlers-custom/expected-bundle.js | 9 +++- .../head-no-whitespace/expected-bundle.js | 9 +++- .../if-block-no-update/expected-bundle.js | 9 +++- .../if-block-simple/expected-bundle.js | 9 +++- .../expected-bundle.js | 9 +++- .../expected-bundle.js | 9 +++- .../inline-style-optimized/expected-bundle.js | 9 +++- .../expected-bundle.js | 9 +++- .../expected-bundle.js | 9 +++- .../legacy-input-type/expected-bundle.js | 9 +++- .../legacy-quote-class/expected-bundle.js | 9 +++- .../samples/media-bindings/expected-bundle.js | 9 +++- .../non-imported-component/expected-bundle.js | 9 +++- .../expected-bundle.js | 9 +++- .../samples/setup-method/expected-bundle.js | 9 +++- test/js/samples/svg-title/expected-bundle.js | 9 +++- test/js/samples/title/expected-bundle.js | 9 +++- .../expected-bundle.js | 9 +++- .../window-binding-scroll/expected-bundle.js | 9 +++- 33 files changed, 279 insertions(+), 33 deletions(-) diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts index 776cf1ab0b..e103f428cf 100644 --- a/src/generators/dom/index.ts +++ b/src/generators/dom/index.ts @@ -375,6 +375,7 @@ export default function dom( if (sigil === '@') { if (name in shared) { if (options.dev && `${name}Dev` in shared) name = `${name}Dev`; + else if (options.immutable && `${name}Immutable` in shared) name = `${name}Immutable`; usedHelpers.add(name); } diff --git a/src/interfaces.ts b/src/interfaces.ts index 9773d330d3..82de8cd047 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -52,6 +52,7 @@ export interface CompileOptions { cssOutputFilename?: string; dev?: boolean; + immutable?: boolean; shared?: boolean | string; cascade?: boolean; hydratable?: boolean; diff --git a/src/shared/index.js b/src/shared/index.js index ef160ebf07..ec8706be6d 100644 --- a/src/shared/index.js +++ b/src/shared/index.js @@ -26,7 +26,25 @@ export function destroyDev(detach) { } export function differs(a, b) { - return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); + 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'; +} + +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; } export function dispatchObservers(component, group, changed, newState, oldState) { @@ -165,6 +183,27 @@ export function _set(newState) { } } +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 (!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 setDev(newState) { if (typeof newState !== 'object') { throw new Error( diff --git a/store.js b/store.js index f31c659080..853d36a52a 100644 --- a/store.js +++ b/store.js @@ -2,12 +2,13 @@ import { assign, blankObject, differs, + differsImmutable, dispatchObservers, get, observe } from './shared.js'; -function Store(state) { +function Store(state, options) { this._observers = { pre: blankObject(), post: blankObject() }; this._changeHandlers = []; this._dependents = []; @@ -16,6 +17,7 @@ function Store(state) { this._sortedComputedProperties = []; this._state = assign({}, state); + this._differs = options && options.immutable ? differsImmutable : differs; } assign(Store.prototype, { @@ -88,7 +90,7 @@ assign(Store.prototype, { if (dirty) { var newValue = fn.apply(null, values); - if (differs(newValue, value)) { + if (store._differs(newValue, value)) { value = newValue; changed[key] = true; state[key] = value; @@ -124,7 +126,7 @@ assign(Store.prototype, { for (var key in newState) { if (this._computed[key]) throw new Error("'" + key + "' is a read-only property"); - if (differs(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 59cd2de125..ffc75c872c 100644 --- a/test/js/samples/collapses-text-around-comments/expected-bundle.js +++ b/test/js/samples/collapses-text-around-comments/expected-bundle.js @@ -52,7 +52,14 @@ function destroy(detach) { } function differs(a, b) { - return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); + 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'; } function dispatchObservers(component, group, changed, newState, oldState) { diff --git a/test/js/samples/component-static/expected-bundle.js b/test/js/samples/component-static/expected-bundle.js index 708ef5be95..970b8e139a 100644 --- a/test/js/samples/component-static/expected-bundle.js +++ b/test/js/samples/component-static/expected-bundle.js @@ -28,7 +28,14 @@ function destroy(detach) { } function differs(a, b) { - return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); + 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'; } function dispatchObservers(component, group, changed, newState, oldState) { diff --git a/test/js/samples/computed-collapsed-if/expected-bundle.js b/test/js/samples/computed-collapsed-if/expected-bundle.js index b39f95a77b..e9285f3bc0 100644 --- a/test/js/samples/computed-collapsed-if/expected-bundle.js +++ b/test/js/samples/computed-collapsed-if/expected-bundle.js @@ -28,7 +28,14 @@ function destroy(detach) { } function differs(a, b) { - return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); + 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'; } function dispatchObservers(component, group, changed, newState, oldState) { diff --git a/test/js/samples/css-media-query/expected-bundle.js b/test/js/samples/css-media-query/expected-bundle.js index 91662053a4..6ccc9200d5 100644 --- a/test/js/samples/css-media-query/expected-bundle.js +++ b/test/js/samples/css-media-query/expected-bundle.js @@ -48,7 +48,14 @@ function destroy(detach) { } function differs(a, b) { - return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); + 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'; } function dispatchObservers(component, group, changed, newState, oldState) { 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 03e5cef1e2..4948afea4d 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js @@ -40,7 +40,14 @@ function destroy(detach) { } function differs(a, b) { - return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); + 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'; } function dispatchObservers(component, group, changed, newState, oldState) { diff --git a/test/js/samples/deconflict-globals/expected-bundle.js b/test/js/samples/deconflict-globals/expected-bundle.js index ba22542c4b..6733b68767 100644 --- a/test/js/samples/deconflict-globals/expected-bundle.js +++ b/test/js/samples/deconflict-globals/expected-bundle.js @@ -28,7 +28,14 @@ function destroy(detach) { } function differs(a, b) { - return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); + 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'; } function dispatchObservers(component, group, changed, newState, oldState) { diff --git a/test/js/samples/do-use-dataset/expected-bundle.js b/test/js/samples/do-use-dataset/expected-bundle.js index 2079e6607c..442afd002e 100644 --- a/test/js/samples/do-use-dataset/expected-bundle.js +++ b/test/js/samples/do-use-dataset/expected-bundle.js @@ -44,7 +44,14 @@ function destroy(detach) { } function differs(a, b) { - return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); + 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'; } function dispatchObservers(component, group, changed, newState, oldState) { 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 efcfcc8f30..3b5681f2ca 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,7 +48,14 @@ function destroy(detach) { } function differs(a, b) { - return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); + 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'; } function dispatchObservers(component, group, changed, newState, oldState) { 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 cf43bbd130..242ac51828 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,7 +48,14 @@ function destroy(detach) { } function differs(a, b) { - return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); + 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'; } function dispatchObservers(component, group, changed, newState, oldState) { 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 e35826e354..ca09f3774f 100644 --- a/test/js/samples/each-block-changed-check/expected-bundle.js +++ b/test/js/samples/each-block-changed-check/expected-bundle.js @@ -60,7 +60,14 @@ function destroy(detach) { } function differs(a, b) { - return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); + 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'; } function dispatchObservers(component, group, changed, newState, oldState) { diff --git a/test/js/samples/event-handlers-custom/expected-bundle.js b/test/js/samples/event-handlers-custom/expected-bundle.js index 43db3035a3..f9e32a0256 100644 --- a/test/js/samples/event-handlers-custom/expected-bundle.js +++ b/test/js/samples/event-handlers-custom/expected-bundle.js @@ -40,7 +40,14 @@ function destroy(detach) { } function differs(a, b) { - return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); + 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'; } function dispatchObservers(component, group, changed, newState, oldState) { diff --git a/test/js/samples/head-no-whitespace/expected-bundle.js b/test/js/samples/head-no-whitespace/expected-bundle.js index 91f894bc30..62aac217d5 100644 --- a/test/js/samples/head-no-whitespace/expected-bundle.js +++ b/test/js/samples/head-no-whitespace/expected-bundle.js @@ -40,7 +40,14 @@ function destroy(detach) { } function differs(a, b) { - return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); + 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'; } function dispatchObservers(component, group, changed, newState, oldState) { 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 b309a25e96..681edc072e 100644 --- a/test/js/samples/if-block-no-update/expected-bundle.js +++ b/test/js/samples/if-block-no-update/expected-bundle.js @@ -44,7 +44,14 @@ function destroy(detach) { } function differs(a, b) { - return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); + 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'; } function dispatchObservers(component, group, changed, newState, oldState) { diff --git a/test/js/samples/if-block-simple/expected-bundle.js b/test/js/samples/if-block-simple/expected-bundle.js index 5084639f4b..9ce6331f44 100644 --- a/test/js/samples/if-block-simple/expected-bundle.js +++ b/test/js/samples/if-block-simple/expected-bundle.js @@ -44,7 +44,14 @@ function destroy(detach) { } function differs(a, b) { - return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); + 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'; } function dispatchObservers(component, group, changed, newState, oldState) { 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 753d61db71..9077eea9d7 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-multiple/expected-bundle.js @@ -44,7 +44,14 @@ function destroy(detach) { } function differs(a, b) { - return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); + 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'; } function dispatchObservers(component, group, changed, newState, oldState) { 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 cf360881b1..7277ff587a 100644 --- a/test/js/samples/inline-style-optimized-url/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-url/expected-bundle.js @@ -44,7 +44,14 @@ function destroy(detach) { } function differs(a, b) { - return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); + 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'; } function dispatchObservers(component, group, changed, newState, oldState) { diff --git a/test/js/samples/inline-style-optimized/expected-bundle.js b/test/js/samples/inline-style-optimized/expected-bundle.js index 38024df4ff..9b3f41768f 100644 --- a/test/js/samples/inline-style-optimized/expected-bundle.js +++ b/test/js/samples/inline-style-optimized/expected-bundle.js @@ -44,7 +44,14 @@ function destroy(detach) { } function differs(a, b) { - return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); + 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'; } function dispatchObservers(component, group, changed, newState, oldState) { diff --git a/test/js/samples/inline-style-unoptimized/expected-bundle.js b/test/js/samples/inline-style-unoptimized/expected-bundle.js index 320c733a43..f1a5a53d7f 100644 --- a/test/js/samples/inline-style-unoptimized/expected-bundle.js +++ b/test/js/samples/inline-style-unoptimized/expected-bundle.js @@ -44,7 +44,14 @@ function destroy(detach) { } function differs(a, b) { - return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); + 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'; } function dispatchObservers(component, group, changed, newState, oldState) { 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 eacaca85a6..b32377763e 100644 --- a/test/js/samples/input-without-blowback-guard/expected-bundle.js +++ b/test/js/samples/input-without-blowback-guard/expected-bundle.js @@ -48,7 +48,14 @@ function destroy(detach) { } function differs(a, b) { - return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); + 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'; } function dispatchObservers(component, group, changed, newState, oldState) { diff --git a/test/js/samples/legacy-input-type/expected-bundle.js b/test/js/samples/legacy-input-type/expected-bundle.js index 7b730f08d9..1dbd32f619 100644 --- a/test/js/samples/legacy-input-type/expected-bundle.js +++ b/test/js/samples/legacy-input-type/expected-bundle.js @@ -46,7 +46,14 @@ function destroy(detach) { } function differs(a, b) { - return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); + 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'; } function dispatchObservers(component, group, changed, newState, oldState) { diff --git a/test/js/samples/legacy-quote-class/expected-bundle.js b/test/js/samples/legacy-quote-class/expected-bundle.js index 499a82c46e..0b203fb4b6 100644 --- a/test/js/samples/legacy-quote-class/expected-bundle.js +++ b/test/js/samples/legacy-quote-class/expected-bundle.js @@ -63,7 +63,14 @@ function destroy(detach) { } function differs(a, b) { - return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); + 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'; } function dispatchObservers(component, group, changed, newState, oldState) { diff --git a/test/js/samples/media-bindings/expected-bundle.js b/test/js/samples/media-bindings/expected-bundle.js index bbd56d8123..ec971167be 100644 --- a/test/js/samples/media-bindings/expected-bundle.js +++ b/test/js/samples/media-bindings/expected-bundle.js @@ -56,7 +56,14 @@ function destroy(detach) { } function differs(a, b) { - return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); + 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'; } function dispatchObservers(component, group, changed, newState, oldState) { diff --git a/test/js/samples/non-imported-component/expected-bundle.js b/test/js/samples/non-imported-component/expected-bundle.js index f8e0722db7..46de1d757e 100644 --- a/test/js/samples/non-imported-component/expected-bundle.js +++ b/test/js/samples/non-imported-component/expected-bundle.js @@ -42,7 +42,14 @@ function destroy(detach) { } function differs(a, b) { - return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); + 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'; } function dispatchObservers(component, group, changed, newState, oldState) { diff --git a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js index e53dd0de5e..b65e0bfc2a 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js @@ -28,7 +28,14 @@ function destroy(detach) { } function differs(a, b) { - return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); + 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'; } function dispatchObservers(component, group, changed, newState, oldState) { diff --git a/test/js/samples/setup-method/expected-bundle.js b/test/js/samples/setup-method/expected-bundle.js index 58ee3a67a0..80bb847692 100644 --- a/test/js/samples/setup-method/expected-bundle.js +++ b/test/js/samples/setup-method/expected-bundle.js @@ -28,7 +28,14 @@ function destroy(detach) { } function differs(a, b) { - return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); + 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'; } function dispatchObservers(component, group, changed, newState, oldState) { diff --git a/test/js/samples/svg-title/expected-bundle.js b/test/js/samples/svg-title/expected-bundle.js index 12f06bcf92..1ee4d64a48 100644 --- a/test/js/samples/svg-title/expected-bundle.js +++ b/test/js/samples/svg-title/expected-bundle.js @@ -48,7 +48,14 @@ function destroy(detach) { } function differs(a, b) { - return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); + 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'; } function dispatchObservers(component, group, changed, newState, oldState) { diff --git a/test/js/samples/title/expected-bundle.js b/test/js/samples/title/expected-bundle.js index 6eb3471b5b..454a1fad0e 100644 --- a/test/js/samples/title/expected-bundle.js +++ b/test/js/samples/title/expected-bundle.js @@ -28,7 +28,14 @@ function destroy(detach) { } function differs(a, b) { - return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); + 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'; } function dispatchObservers(component, group, changed, newState, oldState) { 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 e2ee1e61fb..9ac57fe215 100644 --- a/test/js/samples/use-elements-as-anchors/expected-bundle.js +++ b/test/js/samples/use-elements-as-anchors/expected-bundle.js @@ -52,7 +52,14 @@ function destroy(detach) { } function differs(a, b) { - return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); + 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'; } function dispatchObservers(component, group, changed, newState, oldState) { diff --git a/test/js/samples/window-binding-scroll/expected-bundle.js b/test/js/samples/window-binding-scroll/expected-bundle.js index a8a932c8b7..457f6d55ea 100644 --- a/test/js/samples/window-binding-scroll/expected-bundle.js +++ b/test/js/samples/window-binding-scroll/expected-bundle.js @@ -48,7 +48,14 @@ function destroy(detach) { } function differs(a, b) { - return a !== b || ((a && typeof a === 'object') || typeof a === 'function'); + 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'; } function dispatchObservers(component, group, changed, newState, oldState) { From 9a1d87494d136d708eb00d46b677cb2d36fb0f04 Mon Sep 17 00:00:00 2001 From: Jacob Wright Date: Sat, 10 Feb 2018 10:23:58 -0700 Subject: [PATCH 2/6] Removes date checks and simplifies NaN checks, adds tests --- src/generators/dom/index.ts | 3 +- src/shared/index.js | 41 +--- .../expected-bundle.js | 12 +- .../expected.js | 3 +- .../component-static/expected-bundle.js | 12 +- test/js/samples/component-static/expected.js | 3 +- .../_config.js | 5 + .../expected-bundle.js | 218 ++++++++++++++++++ .../expected.js | 49 ++++ .../input.html | 8 + .../computed-collapsed-if/expected-bundle.js | 16 +- .../samples/computed-collapsed-if/expected.js | 5 +- .../css-media-query/expected-bundle.js | 12 +- test/js/samples/css-media-query/expected.js | 3 +- .../expected-bundle.js | 12 +- .../css-shadow-dom-keyframes/expected.js | 3 +- .../deconflict-globals/expected-bundle.js | 12 +- .../js/samples/deconflict-globals/expected.js | 3 +- .../samples/do-use-dataset/expected-bundle.js | 12 +- test/js/samples/do-use-dataset/expected.js | 3 +- .../expected-bundle.js | 12 +- .../dont-use-dataset-in-legacy/expected.js | 3 +- .../expected-bundle.js | 12 +- .../dont-use-dataset-in-svg/expected.js | 3 +- .../expected-bundle.js | 12 +- .../each-block-changed-check/expected.js | 3 +- .../event-handlers-custom/expected-bundle.js | 12 +- .../samples/event-handlers-custom/expected.js | 3 +- .../head-no-whitespace/expected-bundle.js | 12 +- .../js/samples/head-no-whitespace/expected.js | 3 +- .../if-block-no-update/expected-bundle.js | 12 +- .../js/samples/if-block-no-update/expected.js | 3 +- .../if-block-simple/expected-bundle.js | 12 +- test/js/samples/if-block-simple/expected.js | 3 +- .../expected-bundle.js | 12 +- .../expected.js | 3 +- .../expected-bundle.js | 12 +- .../inline-style-optimized-url/expected.js | 3 +- .../inline-style-optimized/expected-bundle.js | 12 +- .../inline-style-optimized/expected.js | 3 +- .../expected-bundle.js | 12 +- .../inline-style-unoptimized/expected.js | 3 +- .../expected-bundle.js | 12 +- .../input-without-blowback-guard/expected.js | 3 +- .../legacy-input-type/expected-bundle.js | 12 +- test/js/samples/legacy-input-type/expected.js | 3 +- .../legacy-quote-class/expected-bundle.js | 12 +- .../js/samples/legacy-quote-class/expected.js | 3 +- .../samples/media-bindings/expected-bundle.js | 12 +- test/js/samples/media-bindings/expected.js | 3 +- .../non-imported-component/expected-bundle.js | 12 +- .../non-imported-component/expected.js | 3 +- .../expected-bundle.js | 12 +- .../onrender-onteardown-rewritten/expected.js | 3 +- .../samples/setup-method/expected-bundle.js | 12 +- test/js/samples/setup-method/expected.js | 3 +- test/js/samples/svg-title/expected-bundle.js | 12 +- test/js/samples/svg-title/expected.js | 3 +- test/js/samples/title/expected-bundle.js | 12 +- test/js/samples/title/expected.js | 3 +- .../expected-bundle.js | 12 +- .../use-elements-as-anchors/expected.js | 3 +- .../window-binding-scroll/expected-bundle.js | 12 +- .../samples/window-binding-scroll/expected.js | 3 +- test/store/index.js | 40 ++++ 65 files changed, 473 insertions(+), 332 deletions(-) create mode 100644 test/js/samples/computed-collapsed-if-immutable/_config.js create mode 100644 test/js/samples/computed-collapsed-if-immutable/expected-bundle.js create mode 100644 test/js/samples/computed-collapsed-if-immutable/expected.js create mode 100644 test/js/samples/computed-collapsed-if-immutable/input.html 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); + }); + }); }); From 9e877d9da10bb6ed0615a655a5d1f362055c9449 Mon Sep 17 00:00:00 2001 From: Jacob Wright Date: Sat, 10 Feb 2018 12:37:33 -0700 Subject: [PATCH 3/6] Makes immutable a component option rather than a compile option This allows components to opt in (or out) of using immutable data checking for greater flexibility in app design. It also removes the compiler option. --- src/generators/Generator.ts | 4 ++ src/generators/dom/index.ts | 3 +- src/interfaces.ts | 1 - src/shared/index.js | 2 + src/validate/js/propValidators/immutable.ts | 11 ++++ src/validate/js/propValidators/index.ts | 2 + .../expected-bundle.js | 7 ++- .../expected.js | 3 +- .../expected-bundle.js | 57 +++++++++++------ .../component-static-immutable/expected.js | 62 +++++++++++++++++++ .../component-static-immutable/input.html | 10 +++ .../component-static/expected-bundle.js | 7 ++- test/js/samples/component-static/expected.js | 3 +- .../_config.js | 5 -- .../expected.js | 49 --------------- .../input.html | 8 --- .../computed-collapsed-if/expected-bundle.js | 7 ++- .../samples/computed-collapsed-if/expected.js | 3 +- .../css-media-query/expected-bundle.js | 7 ++- test/js/samples/css-media-query/expected.js | 3 +- .../expected-bundle.js | 7 ++- .../css-shadow-dom-keyframes/expected.js | 3 +- .../deconflict-globals/expected-bundle.js | 7 ++- .../js/samples/deconflict-globals/expected.js | 3 +- .../samples/do-use-dataset/expected-bundle.js | 7 ++- test/js/samples/do-use-dataset/expected.js | 3 +- .../expected-bundle.js | 7 ++- .../dont-use-dataset-in-legacy/expected.js | 3 +- .../expected-bundle.js | 7 ++- .../dont-use-dataset-in-svg/expected.js | 3 +- .../expected-bundle.js | 7 ++- .../each-block-changed-check/expected.js | 3 +- .../event-handlers-custom/expected-bundle.js | 7 ++- .../samples/event-handlers-custom/expected.js | 3 +- .../head-no-whitespace/expected-bundle.js | 7 ++- .../js/samples/head-no-whitespace/expected.js | 3 +- .../if-block-no-update/expected-bundle.js | 7 ++- .../js/samples/if-block-no-update/expected.js | 3 +- .../if-block-simple/expected-bundle.js | 7 ++- test/js/samples/if-block-simple/expected.js | 3 +- .../expected-bundle.js | 7 ++- .../expected.js | 3 +- .../expected-bundle.js | 7 ++- .../inline-style-optimized-url/expected.js | 3 +- .../inline-style-optimized/expected-bundle.js | 7 ++- .../inline-style-optimized/expected.js | 3 +- .../expected-bundle.js | 7 ++- .../inline-style-unoptimized/expected.js | 3 +- .../expected-bundle.js | 7 ++- .../input-without-blowback-guard/expected.js | 3 +- .../legacy-input-type/expected-bundle.js | 7 ++- test/js/samples/legacy-input-type/expected.js | 3 +- .../legacy-quote-class/expected-bundle.js | 7 ++- .../js/samples/legacy-quote-class/expected.js | 3 +- .../samples/media-bindings/expected-bundle.js | 7 ++- test/js/samples/media-bindings/expected.js | 3 +- .../non-imported-component/expected-bundle.js | 7 ++- .../non-imported-component/expected.js | 3 +- .../expected-bundle.js | 7 ++- .../onrender-onteardown-rewritten/expected.js | 3 +- .../samples/setup-method/expected-bundle.js | 7 ++- test/js/samples/setup-method/expected.js | 3 +- test/js/samples/svg-title/expected-bundle.js | 7 ++- test/js/samples/svg-title/expected.js | 3 +- test/js/samples/title/expected-bundle.js | 7 ++- test/js/samples/title/expected.js | 3 +- .../expected-bundle.js | 7 ++- .../use-elements-as-anchors/expected.js | 3 +- .../window-binding-scroll/expected-bundle.js | 7 ++- .../samples/window-binding-scroll/expected.js | 3 +- 70 files changed, 333 insertions(+), 171 deletions(-) create mode 100644 src/validate/js/propValidators/immutable.ts rename test/js/samples/{computed-collapsed-if-immutable => component-static-immutable}/expected-bundle.js (80%) create mode 100644 test/js/samples/component-static-immutable/expected.js create mode 100644 test/js/samples/component-static-immutable/input.html delete mode 100644 test/js/samples/computed-collapsed-if-immutable/_config.js delete mode 100644 test/js/samples/computed-collapsed-if-immutable/expected.js delete mode 100644 test/js/samples/computed-collapsed-if-immutable/input.html diff --git a/src/generators/Generator.ts b/src/generators/Generator.ts index 1f48424c95..35bb2e9859 100644 --- a/src/generators/Generator.ts +++ b/src/generators/Generator.ts @@ -626,6 +626,10 @@ export default class Generator { addDeclaration('store', templateProperties.store.value); } + if (templateProperties.immutable) { + addDeclaration('immutable', templateProperties.immutable.value); + } + if (templateProperties.tag) { this.tag = templateProperties.tag.value.value; } diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts index acf161642d..c1a23784b0 100644 --- a/src/generators/dom/index.ts +++ b/src/generators/dom/index.ts @@ -207,8 +207,8 @@ export default function dom( ${options.dev && `this._debugName = '${debugName}';`} ${options.dev && !generator.customElement && `if (!options || (!options.target && !options.root)) throw new Error("'target' is a required option");`} + ${templateProperties.immutable && `if (!('immutable' in options)) options = assign({ immutable: %immutable }, options);`} @init(this, options); - this._differs = @differs; ${templateProperties.store && `this.store = %store();`} ${generator.usesRefs && `this.refs = {};`} this._state = @assign(${initialState.join(', ')}); @@ -376,7 +376,6 @@ export default function dom( if (sigil === '@') { if (name in shared) { if (options.dev && `${name}Dev` in shared) name = `${name}Dev`; - else if (options.immutable && `${name}Immutable` in shared) name = `${name}Immutable`; usedHelpers.add(name); } diff --git a/src/interfaces.ts b/src/interfaces.ts index 82de8cd047..9773d330d3 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -52,7 +52,6 @@ export interface CompileOptions { cssOutputFilename?: string; dev?: boolean; - immutable?: boolean; shared?: boolean | string; cascade?: boolean; hydratable?: boolean; diff --git a/src/shared/index.js b/src/shared/index.js index 0005569532..8506a5ed56 100644 --- a/src/shared/index.js +++ b/src/shared/index.js @@ -76,6 +76,8 @@ export function init(component, options) { component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; + var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; + component._differs = immutable ? differsImmutable : differs; } export function observe(key, callback, options) { diff --git a/src/validate/js/propValidators/immutable.ts b/src/validate/js/propValidators/immutable.ts new file mode 100644 index 0000000000..20e475340d --- /dev/null +++ b/src/validate/js/propValidators/immutable.ts @@ -0,0 +1,11 @@ +import { Validator } from '../../'; +import { Node } from '../../../interfaces'; + +export default function tag(validator: Validator, prop: Node) { + if (prop.value.type !== 'Literal' || typeof prop.value.value !== 'boolean') { + validator.error( + `'immutable' must be a boolean literal`, + prop.value.start + ); + } +} diff --git a/src/validate/js/propValidators/index.ts b/src/validate/js/propValidators/index.ts index 942c757601..05819b0837 100644 --- a/src/validate/js/propValidators/index.ts +++ b/src/validate/js/propValidators/index.ts @@ -15,6 +15,7 @@ import tag from './tag'; import transitions from './transitions'; import setup from './setup'; import store from './store'; +import immutable from './immutable'; export default { data, @@ -34,4 +35,5 @@ export default { transitions, setup, store, + immutable, }; 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 ba89e7777b..15e441a2b3 100644 --- a/test/js/samples/collapses-text-around-comments/expected-bundle.js +++ b/test/js/samples/collapses-text-around-comments/expected-bundle.js @@ -55,6 +55,10 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } +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; @@ -98,6 +102,8 @@ function init(component, options) { component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; + var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; + component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { @@ -243,7 +249,6 @@ 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 a76fb36edf..aea4721e36 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, differs, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; +import { appendNode, assign, createElement, createText, detachNode, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; function data() { return { foo: 42 } @@ -51,7 +51,6 @@ 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/computed-collapsed-if-immutable/expected-bundle.js b/test/js/samples/component-static-immutable/expected-bundle.js similarity index 80% rename from test/js/samples/computed-collapsed-if-immutable/expected-bundle.js rename to test/js/samples/component-static-immutable/expected-bundle.js index 509aa9328f..580ce5287b 100644 --- a/test/js/samples/computed-collapsed-if-immutable/expected-bundle.js +++ b/test/js/samples/component-static-immutable/expected-bundle.js @@ -27,6 +27,10 @@ function destroy(detach) { this._fragment = this._state = null; } +function differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + function differsImmutable(a, b) { return a != a ? b == b : a !== b; } @@ -74,6 +78,8 @@ function init(component, options) { component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; + var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; + component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { @@ -169,50 +175,63 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ -function a(x) { - return x * 2; -} +var Nested = window.Nested; -function b(x) { - return x * 3; -} +var immutable = true; function create_main_fragment(state, component) { + var nested = new Nested({ + root: component.root, + data: { foo: "bar" } + }); + return { - c: noop, + c: function create() { + nested._fragment.c(); + }, - m: noop, + m: function mount(target, anchor) { + nested._mount(target, anchor); + }, p: noop, - u: noop, + u: function unmount() { + nested._unmount(); + }, - d: noop + d: function destroy$$1() { + nested.destroy(false); + } }; } function SvelteComponent(options) { + if (!('immutable' in options)) options = assign({ immutable: immutable }, options); init(this, options); - this._differs = differsImmutable; this._state = assign({}, options.data); - this._recompute({ x: 1 }, this._state); + + if (!options.root) { + this._oncreate = []; + this._beforecreate = []; + this._aftercreate = []; + } this._fragment = create_main_fragment(this._state, this); if (options.target) { this._fragment.c(); this._fragment.m(options.target, options.anchor || null); + + this._lock = true; + callAll(this._beforecreate); + callAll(this._oncreate); + callAll(this._aftercreate); + this._lock = false; } } 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/component-static-immutable/expected.js b/test/js/samples/component-static-immutable/expected.js new file mode 100644 index 0000000000..57ce7c1a85 --- /dev/null +++ b/test/js/samples/component-static-immutable/expected.js @@ -0,0 +1,62 @@ +/* generated by Svelte vX.Y.Z */ +import { assign, callAll, init, noop, proto } from "svelte/shared.js"; + +var Nested = window.Nested; + +var immutable = true; + +function create_main_fragment(state, component) { + + var nested = new Nested({ + root: component.root, + data: { foo: "bar" } + }); + + return { + c: function create() { + nested._fragment.c(); + }, + + m: function mount(target, anchor) { + nested._mount(target, anchor); + }, + + p: noop, + + u: function unmount() { + nested._unmount(); + }, + + d: function destroy() { + nested.destroy(false); + } + }; +} + +function SvelteComponent(options) { + if (!('immutable' in options)) options = assign({ immutable: immutable }, options); + init(this, options); + this._state = assign({}, options.data); + + if (!options.root) { + this._oncreate = []; + this._beforecreate = []; + this._aftercreate = []; + } + + this._fragment = create_main_fragment(this._state, this); + + if (options.target) { + this._fragment.c(); + this._fragment.m(options.target, options.anchor || null); + + this._lock = true; + callAll(this._beforecreate); + callAll(this._oncreate); + callAll(this._aftercreate); + this._lock = false; + } +} + +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/component-static-immutable/input.html b/test/js/samples/component-static-immutable/input.html new file mode 100644 index 0000000000..df6c82ea81 --- /dev/null +++ b/test/js/samples/component-static-immutable/input.html @@ -0,0 +1,10 @@ + + + \ No newline at end of file diff --git a/test/js/samples/component-static/expected-bundle.js b/test/js/samples/component-static/expected-bundle.js index b28b38ddb6..161fc25d9d 100644 --- a/test/js/samples/component-static/expected-bundle.js +++ b/test/js/samples/component-static/expected-bundle.js @@ -31,6 +31,10 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } +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; @@ -74,6 +78,8 @@ function init(component, options) { component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; + var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; + component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { @@ -201,7 +207,6 @@ 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 de06c6fb2d..d75cce1253 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, differs, init, noop, proto } from "svelte/shared.js"; +import { assign, callAll, init, noop, proto } from "svelte/shared.js"; var Nested = window.Nested; @@ -33,7 +33,6 @@ 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 deleted file mode 100644 index 06713941e0..0000000000 --- a/test/js/samples/computed-collapsed-if-immutable/_config.js +++ /dev/null @@ -1,5 +0,0 @@ -export default { - options: { - immutable: true - } -}; \ No newline at end of file diff --git a/test/js/samples/computed-collapsed-if-immutable/expected.js b/test/js/samples/computed-collapsed-if-immutable/expected.js deleted file mode 100644 index b5beba1695..0000000000 --- a/test/js/samples/computed-collapsed-if-immutable/expected.js +++ /dev/null @@ -1,49 +0,0 @@ -/* 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 deleted file mode 100644 index a68513b860..0000000000 --- a/test/js/samples/computed-collapsed-if-immutable/input.html +++ /dev/null @@ -1,8 +0,0 @@ - \ 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 475b5d3491..41cf402472 100644 --- a/test/js/samples/computed-collapsed-if/expected-bundle.js +++ b/test/js/samples/computed-collapsed-if/expected-bundle.js @@ -31,6 +31,10 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } +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; @@ -74,6 +78,8 @@ function init(component, options) { component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; + var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; + component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { @@ -194,7 +200,6 @@ 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); diff --git a/test/js/samples/computed-collapsed-if/expected.js b/test/js/samples/computed-collapsed-if/expected.js index c0765a4115..085365f4c5 100644 --- a/test/js/samples/computed-collapsed-if/expected.js +++ b/test/js/samples/computed-collapsed-if/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z */ -import { assign, differs, init, noop, proto } from "svelte/shared.js"; +import { assign, init, noop, proto } from "svelte/shared.js"; function a(x) { return x * 2; @@ -26,7 +26,6 @@ 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); diff --git a/test/js/samples/css-media-query/expected-bundle.js b/test/js/samples/css-media-query/expected-bundle.js index cfed183001..f70404e499 100644 --- a/test/js/samples/css-media-query/expected-bundle.js +++ b/test/js/samples/css-media-query/expected-bundle.js @@ -51,6 +51,10 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } +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; @@ -94,6 +98,8 @@ function init(component, options) { component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; + var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; + component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { @@ -229,7 +235,6 @@ 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 61e78032e8..37afa6b42a 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, differs, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; +import { appendNode, assign, createElement, detachNode, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; function encapsulateStyles(node) { setAttribute(node, "svelte-3905933315", ""); @@ -41,7 +41,6 @@ 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 2684f5ddb7..216ad97fe2 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js @@ -43,6 +43,10 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } +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; @@ -86,6 +90,8 @@ function init(component, options) { component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; + var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; + component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { @@ -209,7 +215,6 @@ 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 de4528ff0e..496586e632 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, differs, init, insertNode, noop, proto } from "svelte/shared.js"; +import { assign, createElement, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var div; @@ -29,7 +29,6 @@ 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 b3e979c0e9..7769b49deb 100644 --- a/test/js/samples/deconflict-globals/expected-bundle.js +++ b/test/js/samples/deconflict-globals/expected-bundle.js @@ -31,6 +31,10 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } +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; @@ -74,6 +78,8 @@ function init(component, options) { component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; + var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; + component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { @@ -196,7 +202,6 @@ 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 95da7a1a0c..8730f4e3c3 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, differs, init, noop, proto } from "svelte/shared.js"; +import { assign, callAll, init, noop, proto } from "svelte/shared.js"; function data_1() { return { @@ -28,7 +28,6 @@ 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 8974c8a808..3b955df698 100644 --- a/test/js/samples/do-use-dataset/expected-bundle.js +++ b/test/js/samples/do-use-dataset/expected-bundle.js @@ -47,6 +47,10 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } +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; @@ -90,6 +94,8 @@ function init(component, options) { component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; + var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; + component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { @@ -225,7 +231,6 @@ 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 cbe6e9ac2b..1ae7417469 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, differs, init, insertNode, noop, proto } from "svelte/shared.js"; +import { assign, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var div, text, div_1; @@ -41,7 +41,6 @@ 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 9f546da356..15c19756cb 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 @@ -51,6 +51,10 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } +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; @@ -94,6 +98,8 @@ function init(component, options) { component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; + var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; + component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { @@ -229,7 +235,6 @@ 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 989b1a47f8..03eef26ced 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, differs, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; +import { assign, createElement, createText, detachNode, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; function create_main_fragment(state, component) { var div, text, div_1; @@ -41,7 +41,6 @@ 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 e6c5fee0c6..ee846b8fb4 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 @@ -51,6 +51,10 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } +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; @@ -94,6 +98,8 @@ function init(component, options) { component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; + var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; + component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { @@ -227,7 +233,6 @@ 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 f96da75975..b87f152298 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, differs, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; +import { appendNode, assign, createSvgElement, detachNode, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; function create_main_fragment(state, component) { var svg, g, g_1; @@ -39,7 +39,6 @@ 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 428e9c739a..d717803108 100644 --- a/test/js/samples/each-block-changed-check/expected-bundle.js +++ b/test/js/samples/each-block-changed-check/expected-bundle.js @@ -63,6 +63,10 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } +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; @@ -106,6 +110,8 @@ function init(component, options) { component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; + var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; + component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { @@ -341,7 +347,6 @@ 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 c436550f07..29a57322e0 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, differs, init, insertNode, noop, proto } from "svelte/shared.js"; +import { appendNode, assign, createElement, createText, destroyEach, detachAfter, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var text, p, text_1; @@ -141,7 +141,6 @@ 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 819b653caa..dbda232f59 100644 --- a/test/js/samples/event-handlers-custom/expected-bundle.js +++ b/test/js/samples/event-handlers-custom/expected-bundle.js @@ -43,6 +43,10 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } +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; @@ -86,6 +90,8 @@ function init(component, options) { component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; + var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; + component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { @@ -226,7 +232,6 @@ 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 1d5ae4b17e..f7862efb62 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, differs, init, insertNode, noop, proto } from "svelte/shared.js"; +import { assign, createElement, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; function foo( node, callback ) { // code goes here @@ -46,7 +46,6 @@ 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 398617dd13..c0ae2a8ba0 100644 --- a/test/js/samples/head-no-whitespace/expected-bundle.js +++ b/test/js/samples/head-no-whitespace/expected-bundle.js @@ -43,6 +43,10 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } +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; @@ -86,6 +90,8 @@ function init(component, options) { component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; + var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; + component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { @@ -216,7 +222,6 @@ 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 d9bee61c62..32a1a5da88 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, differs, init, noop, proto } from "svelte/shared.js"; +import { appendNode, assign, createElement, detachNode, init, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var meta, meta_1; @@ -36,7 +36,6 @@ 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 b3dc0c6b13..31d618922e 100644 --- a/test/js/samples/if-block-no-update/expected-bundle.js +++ b/test/js/samples/if-block-no-update/expected-bundle.js @@ -47,6 +47,10 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } +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; @@ -90,6 +94,8 @@ function init(component, options) { component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; + var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; + component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { @@ -274,7 +280,6 @@ 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 59c54d1ad7..8f030e4e53 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, differs, init, insertNode, noop, proto } from "svelte/shared.js"; +import { assign, createComment, createElement, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var if_block_anchor; @@ -90,7 +90,6 @@ 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 9dac6d03a9..f36462efad 100644 --- a/test/js/samples/if-block-simple/expected-bundle.js +++ b/test/js/samples/if-block-simple/expected-bundle.js @@ -47,6 +47,10 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } +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; @@ -90,6 +94,8 @@ function init(component, options) { component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; + var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; + component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { @@ -250,7 +256,6 @@ 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 667640451f..0b9fbece70 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, differs, init, insertNode, noop, proto } from "svelte/shared.js"; +import { assign, createComment, createElement, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var if_block_anchor; @@ -66,7 +66,6 @@ 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 8843db047b..57402a155a 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-multiple/expected-bundle.js @@ -47,6 +47,10 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } +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; @@ -90,6 +94,8 @@ function init(component, options) { component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; + var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; + component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { @@ -223,7 +229,6 @@ 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 0b0aca132b..77173460e2 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, differs, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; +import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; function create_main_fragment(state, component) { var div; @@ -39,7 +39,6 @@ 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 e88379a4e4..069cc003b7 100644 --- a/test/js/samples/inline-style-optimized-url/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-url/expected-bundle.js @@ -47,6 +47,10 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } +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; @@ -90,6 +94,8 @@ function init(component, options) { component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; + var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; + component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { @@ -218,7 +224,6 @@ 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 1d8d5c467a..bed00356f6 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, differs, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; +import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; function create_main_fragment(state, component) { var div; @@ -34,7 +34,6 @@ 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 a1b8278e87..643017655d 100644 --- a/test/js/samples/inline-style-optimized/expected-bundle.js +++ b/test/js/samples/inline-style-optimized/expected-bundle.js @@ -47,6 +47,10 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } +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; @@ -90,6 +94,8 @@ function init(component, options) { component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; + var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; + component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { @@ -218,7 +224,6 @@ 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 7f4f19248b..7f873e296c 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, differs, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; +import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; function create_main_fragment(state, component) { var div; @@ -34,7 +34,6 @@ 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 9db0da26fe..906bf21bb5 100644 --- a/test/js/samples/inline-style-unoptimized/expected-bundle.js +++ b/test/js/samples/inline-style-unoptimized/expected-bundle.js @@ -47,6 +47,10 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } +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; @@ -90,6 +94,8 @@ function init(component, options) { component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; + var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; + component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { @@ -229,7 +235,6 @@ 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 0e53480fe8..4c4d38d2bf 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, differs, init, insertNode, noop, proto } from "svelte/shared.js"; +import { assign, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var div, text, div_1, div_1_style_value; @@ -45,7 +45,6 @@ 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 fb3f125b00..a02405f10a 100644 --- a/test/js/samples/input-without-blowback-guard/expected-bundle.js +++ b/test/js/samples/input-without-blowback-guard/expected-bundle.js @@ -51,6 +51,10 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } +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; @@ -94,6 +98,8 @@ function init(component, options) { component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; + var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; + component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { @@ -229,7 +235,6 @@ 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 9342b25ec9..03f27ab6d9 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, differs, init, insertNode, proto, removeListener } from "svelte/shared.js"; +import { addListener, assign, createElement, detachNode, init, insertNode, proto, removeListener } from "svelte/shared.js"; function create_main_fragment(state, component) { var input; @@ -41,7 +41,6 @@ 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 8b6e2faa8f..b54727a24c 100644 --- a/test/js/samples/legacy-input-type/expected-bundle.js +++ b/test/js/samples/legacy-input-type/expected-bundle.js @@ -49,6 +49,10 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } +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; @@ -92,6 +96,8 @@ function init(component, options) { component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; + var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; + component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { @@ -216,7 +222,6 @@ 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 22d71f036d..719f550044 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, differs, init, insertNode, noop, proto, setInputType } from "svelte/shared.js"; +import { assign, createElement, detachNode, init, insertNode, noop, proto, setInputType } from "svelte/shared.js"; function create_main_fragment(state, component) { var input; @@ -30,7 +30,6 @@ 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 b4900a16b5..3177f32f16 100644 --- a/test/js/samples/legacy-quote-class/expected-bundle.js +++ b/test/js/samples/legacy-quote-class/expected-bundle.js @@ -66,6 +66,10 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } +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; @@ -109,6 +113,8 @@ function init(component, options) { component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; + var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; + component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { @@ -241,7 +247,6 @@ 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 c4421f91cd..0b49103c47 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, differs, init, insertNode, noop, proto } from "svelte/shared.js"; +import { assign, children, claimElement, createElement, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var div; @@ -38,7 +38,6 @@ 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 2eacb53f8c..7a258f8965 100644 --- a/test/js/samples/media-bindings/expected-bundle.js +++ b/test/js/samples/media-bindings/expected-bundle.js @@ -59,6 +59,10 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } +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; @@ -102,6 +106,8 @@ function init(component, options) { component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; + var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; + component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { @@ -282,7 +288,6 @@ 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 503228ce06..ae80f288f6 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, differs, init, insertNode, proto, removeListener, timeRangesToArray } from "svelte/shared.js"; +import { addListener, assign, callAll, createElement, detachNode, 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,7 +86,6 @@ 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 9cba5b8bfb..2799a85ebe 100644 --- a/test/js/samples/non-imported-component/expected-bundle.js +++ b/test/js/samples/non-imported-component/expected-bundle.js @@ -45,6 +45,10 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } +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; @@ -88,6 +92,8 @@ function init(component, options) { component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; + var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; + component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { @@ -224,7 +230,6 @@ 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 c35b4f88a7..e7fc2c7255 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, differs, init, insertNode, noop, proto } from "svelte/shared.js"; +import { assign, callAll, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; import Imported from 'Imported.html'; @@ -45,7 +45,6 @@ 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 26f52231fc..049ba0d86a 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js @@ -31,6 +31,10 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } +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; @@ -74,6 +78,8 @@ function init(component, options) { component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; + var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; + component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { @@ -190,7 +196,6 @@ 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 02203f83c0..51763c0b00 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, differs, init, noop, proto } from "svelte/shared.js"; +import { assign, callAll, init, noop, proto } from "svelte/shared.js"; function oncreate() {}; @@ -22,7 +22,6 @@ 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 103bf174ac..388bb495bc 100644 --- a/test/js/samples/setup-method/expected-bundle.js +++ b/test/js/samples/setup-method/expected-bundle.js @@ -31,6 +31,10 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } +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; @@ -74,6 +78,8 @@ function init(component, options) { component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; + var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; + component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { @@ -202,7 +208,6 @@ 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 5b306a12e7..092a32ed3b 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, differs, init, noop, proto } from "svelte/shared.js"; +import { assign, init, noop, proto } from "svelte/shared.js"; var methods = { foo ( bar ) { @@ -34,7 +34,6 @@ 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 2050f6dcfe..46880a584c 100644 --- a/test/js/samples/svg-title/expected-bundle.js +++ b/test/js/samples/svg-title/expected-bundle.js @@ -51,6 +51,10 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } +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; @@ -94,6 +98,8 @@ function init(component, options) { component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; + var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; + component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { @@ -217,7 +223,6 @@ 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 6c5d08ca00..39ccf227c0 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, differs, init, insertNode, noop, proto } from "svelte/shared.js"; +import { appendNode, assign, createSvgElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var svg, title, text; @@ -29,7 +29,6 @@ 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 2fcc0b6197..4e70625f70 100644 --- a/test/js/samples/title/expected-bundle.js +++ b/test/js/samples/title/expected-bundle.js @@ -31,6 +31,10 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } +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; @@ -74,6 +78,8 @@ function init(component, options) { component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; + var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; + component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { @@ -193,7 +199,6 @@ 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 e15441fbdc..6aa903d25e 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, differs, init, noop, proto } from "svelte/shared.js"; +import { assign, init, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var title_value; @@ -25,7 +25,6 @@ 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 e22e431d53..2045954b41 100644 --- a/test/js/samples/use-elements-as-anchors/expected-bundle.js +++ b/test/js/samples/use-elements-as-anchors/expected-bundle.js @@ -55,6 +55,10 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } +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; @@ -98,6 +102,8 @@ function init(component, options) { component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; + var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; + component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { @@ -440,7 +446,6 @@ 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 0b45ca8679..d2609c45b0 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, differs, init, insertNode, noop, proto } from "svelte/shared.js"; +import { appendNode, assign, createComment, createElement, createText, detachNode, 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,7 +248,6 @@ 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 97231f4bb6..b0014988b7 100644 --- a/test/js/samples/window-binding-scroll/expected-bundle.js +++ b/test/js/samples/window-binding-scroll/expected-bundle.js @@ -51,6 +51,10 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } +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; @@ -94,6 +98,8 @@ function init(component, options) { component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; + var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; + component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { @@ -241,7 +247,6 @@ 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 55bc0eb53a..70eae003d7 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, differs, init, insertNode, proto } from "svelte/shared.js"; +import { appendNode, assign, createElement, createText, detachNode, 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,7 +53,6 @@ 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; From 405c4f637109275e6414b29c7cc1f9439869eea4 Mon Sep 17 00:00:00 2001 From: Jacob Wright Date: Sat, 10 Feb 2018 23:54:33 -0700 Subject: [PATCH 4/6] Adding compiler option for immutable back in This will keep existing code smaller and _mostly_ only add size when using the `immutable` compiler option. --- src/generators/dom/index.ts | 5 ++++- src/interfaces.ts | 1 + src/shared/index.js | 3 +-- src/validate/js/propValidators/immutable.ts | 2 +- .../collapses-text-around-comments/expected-bundle.js | 7 +------ test/js/samples/component-static-immutable/_config.js | 5 +++++ .../samples/component-static-immutable/expected-bundle.js | 7 ++++--- test/js/samples/component-static-immutable/expected.js | 6 ++++-- test/js/samples/component-static/expected-bundle.js | 7 +------ test/js/samples/computed-collapsed-if/expected-bundle.js | 7 +------ test/js/samples/css-media-query/expected-bundle.js | 7 +------ .../js/samples/css-shadow-dom-keyframes/expected-bundle.js | 7 +------ test/js/samples/deconflict-globals/expected-bundle.js | 7 +------ test/js/samples/do-use-dataset/expected-bundle.js | 7 +------ .../samples/dont-use-dataset-in-legacy/expected-bundle.js | 7 +------ test/js/samples/dont-use-dataset-in-svg/expected-bundle.js | 7 +------ .../js/samples/each-block-changed-check/expected-bundle.js | 7 +------ test/js/samples/event-handlers-custom/expected-bundle.js | 7 +------ test/js/samples/head-no-whitespace/expected-bundle.js | 7 +------ test/js/samples/if-block-no-update/expected-bundle.js | 7 +------ test/js/samples/if-block-simple/expected-bundle.js | 7 +------ .../inline-style-optimized-multiple/expected-bundle.js | 7 +------ .../samples/inline-style-optimized-url/expected-bundle.js | 7 +------ test/js/samples/inline-style-optimized/expected-bundle.js | 7 +------ .../js/samples/inline-style-unoptimized/expected-bundle.js | 7 +------ .../input-without-blowback-guard/expected-bundle.js | 7 +------ test/js/samples/legacy-input-type/expected-bundle.js | 7 +------ test/js/samples/legacy-quote-class/expected-bundle.js | 7 +------ test/js/samples/media-bindings/expected-bundle.js | 7 +------ test/js/samples/non-imported-component/expected-bundle.js | 7 +------ .../onrender-onteardown-rewritten/expected-bundle.js | 7 +------ test/js/samples/setup-method/expected-bundle.js | 7 +------ test/js/samples/svg-title/expected-bundle.js | 7 +------ test/js/samples/title/expected-bundle.js | 7 +------ test/js/samples/use-elements-as-anchors/expected-bundle.js | 7 +------ test/js/samples/window-binding-scroll/expected-bundle.js | 7 +------ 36 files changed, 49 insertions(+), 183 deletions(-) create mode 100644 test/js/samples/component-static-immutable/_config.js diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts index c1a23784b0..dc4dafd536 100644 --- a/src/generators/dom/index.ts +++ b/src/generators/dom/index.ts @@ -207,8 +207,11 @@ export default function dom( ${options.dev && `this._debugName = '${debugName}';`} ${options.dev && !generator.customElement && `if (!options || (!options.target && !options.root)) throw new Error("'target' is a required option");`} - ${templateProperties.immutable && `if (!('immutable' in options)) options = assign({ immutable: %immutable }, options);`} @init(this, options); + ${options.immutable && deindent` + if (options.immutable !== undefined ? options.immutable : ${templateProperties.immutable && '%immutable' || 'this.root.options.immutable'}) { + this._differs = @differsImmutable; + }`} ${templateProperties.store && `this.store = %store();`} ${generator.usesRefs && `this.refs = {};`} this._state = @assign(${initialState.join(', ')}); diff --git a/src/interfaces.ts b/src/interfaces.ts index 9773d330d3..82de8cd047 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -52,6 +52,7 @@ export interface CompileOptions { cssOutputFilename?: string; dev?: boolean; + immutable?: boolean; shared?: boolean | string; cascade?: boolean; hydratable?: boolean; diff --git a/src/shared/index.js b/src/shared/index.js index 8506a5ed56..8996ee378a 100644 --- a/src/shared/index.js +++ b/src/shared/index.js @@ -72,12 +72,11 @@ export function init(component, options) { component._observers = { pre: blankObject(), post: blankObject() }; component._handlers = blankObject(); component._bind = options._bind; + component._differs = differs; component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; - var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; - component._differs = immutable ? differsImmutable : differs; } export function observe(key, callback, options) { diff --git a/src/validate/js/propValidators/immutable.ts b/src/validate/js/propValidators/immutable.ts index 20e475340d..b54521d9e4 100644 --- a/src/validate/js/propValidators/immutable.ts +++ b/src/validate/js/propValidators/immutable.ts @@ -1,7 +1,7 @@ import { Validator } from '../../'; import { Node } from '../../../interfaces'; -export default function tag(validator: Validator, prop: Node) { +export default function immutable(validator: Validator, prop: Node) { if (prop.value.type !== 'Literal' || typeof prop.value.value !== 'boolean') { validator.error( `'immutable' must be a boolean literal`, 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 15e441a2b3..72b12b5ef4 100644 --- a/test/js/samples/collapses-text-around-comments/expected-bundle.js +++ b/test/js/samples/collapses-text-around-comments/expected-bundle.js @@ -55,10 +55,6 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -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; @@ -98,12 +94,11 @@ function init(component, options) { component._observers = { pre: blankObject(), post: blankObject() }; component._handlers = blankObject(); component._bind = options._bind; + component._differs = differs; component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; - var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; - component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { diff --git a/test/js/samples/component-static-immutable/_config.js b/test/js/samples/component-static-immutable/_config.js new file mode 100644 index 0000000000..06713941e0 --- /dev/null +++ b/test/js/samples/component-static-immutable/_config.js @@ -0,0 +1,5 @@ +export default { + options: { + immutable: true + } +}; \ No newline at end of file diff --git a/test/js/samples/component-static-immutable/expected-bundle.js b/test/js/samples/component-static-immutable/expected-bundle.js index 580ce5287b..500322d902 100644 --- a/test/js/samples/component-static-immutable/expected-bundle.js +++ b/test/js/samples/component-static-immutable/expected-bundle.js @@ -74,12 +74,11 @@ function init(component, options) { component._observers = { pre: blankObject(), post: blankObject() }; component._handlers = blankObject(); component._bind = options._bind; + component._differs = differs; component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; - var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; - component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { @@ -208,8 +207,10 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - if (!('immutable' in options)) options = assign({ immutable: immutable }, options); init(this, options); + if (options.immutable !== undefined ? options.immutable : immutable) { + this._differs = differsImmutable; + } this._state = assign({}, options.data); if (!options.root) { diff --git a/test/js/samples/component-static-immutable/expected.js b/test/js/samples/component-static-immutable/expected.js index 57ce7c1a85..811d5c50c4 100644 --- a/test/js/samples/component-static-immutable/expected.js +++ b/test/js/samples/component-static-immutable/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, differsImmutable, init, noop, proto } from "svelte/shared.js"; var Nested = window.Nested; @@ -34,8 +34,10 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - if (!('immutable' in options)) options = assign({ immutable: immutable }, options); init(this, options); + if (options.immutable !== undefined ? options.immutable : immutable) { + this._differs = differsImmutable; + } this._state = assign({}, options.data); if (!options.root) { diff --git a/test/js/samples/component-static/expected-bundle.js b/test/js/samples/component-static/expected-bundle.js index 161fc25d9d..b89784944c 100644 --- a/test/js/samples/component-static/expected-bundle.js +++ b/test/js/samples/component-static/expected-bundle.js @@ -31,10 +31,6 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -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; @@ -74,12 +70,11 @@ function init(component, options) { component._observers = { pre: blankObject(), post: blankObject() }; component._handlers = blankObject(); component._bind = options._bind; + component._differs = differs; component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; - var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; - component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { diff --git a/test/js/samples/computed-collapsed-if/expected-bundle.js b/test/js/samples/computed-collapsed-if/expected-bundle.js index 41cf402472..b88fbb5e47 100644 --- a/test/js/samples/computed-collapsed-if/expected-bundle.js +++ b/test/js/samples/computed-collapsed-if/expected-bundle.js @@ -31,10 +31,6 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -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; @@ -74,12 +70,11 @@ function init(component, options) { component._observers = { pre: blankObject(), post: blankObject() }; component._handlers = blankObject(); component._bind = options._bind; + component._differs = differs; component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; - var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; - component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { diff --git a/test/js/samples/css-media-query/expected-bundle.js b/test/js/samples/css-media-query/expected-bundle.js index f70404e499..606b5dc9e8 100644 --- a/test/js/samples/css-media-query/expected-bundle.js +++ b/test/js/samples/css-media-query/expected-bundle.js @@ -51,10 +51,6 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -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; @@ -94,12 +90,11 @@ function init(component, options) { component._observers = { pre: blankObject(), post: blankObject() }; component._handlers = blankObject(); component._bind = options._bind; + component._differs = differs; component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; - var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; - component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { 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 216ad97fe2..0cc67aa9bc 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js @@ -43,10 +43,6 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -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; @@ -86,12 +82,11 @@ function init(component, options) { component._observers = { pre: blankObject(), post: blankObject() }; component._handlers = blankObject(); component._bind = options._bind; + component._differs = differs; component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; - var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; - component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { diff --git a/test/js/samples/deconflict-globals/expected-bundle.js b/test/js/samples/deconflict-globals/expected-bundle.js index 7769b49deb..1a1e25de5a 100644 --- a/test/js/samples/deconflict-globals/expected-bundle.js +++ b/test/js/samples/deconflict-globals/expected-bundle.js @@ -31,10 +31,6 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -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; @@ -74,12 +70,11 @@ function init(component, options) { component._observers = { pre: blankObject(), post: blankObject() }; component._handlers = blankObject(); component._bind = options._bind; + component._differs = differs; component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; - var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; - component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { diff --git a/test/js/samples/do-use-dataset/expected-bundle.js b/test/js/samples/do-use-dataset/expected-bundle.js index 3b955df698..e3532c976a 100644 --- a/test/js/samples/do-use-dataset/expected-bundle.js +++ b/test/js/samples/do-use-dataset/expected-bundle.js @@ -47,10 +47,6 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -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; @@ -90,12 +86,11 @@ function init(component, options) { component._observers = { pre: blankObject(), post: blankObject() }; component._handlers = blankObject(); component._bind = options._bind; + component._differs = differs; component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; - var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; - component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { 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 15c19756cb..df67cf01e8 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 @@ -51,10 +51,6 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -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; @@ -94,12 +90,11 @@ function init(component, options) { component._observers = { pre: blankObject(), post: blankObject() }; component._handlers = blankObject(); component._bind = options._bind; + component._differs = differs; component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; - var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; - component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { 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 ee846b8fb4..55fd993d32 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 @@ -51,10 +51,6 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -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; @@ -94,12 +90,11 @@ function init(component, options) { component._observers = { pre: blankObject(), post: blankObject() }; component._handlers = blankObject(); component._bind = options._bind; + component._differs = differs; component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; - var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; - component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { 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 d717803108..524789a51a 100644 --- a/test/js/samples/each-block-changed-check/expected-bundle.js +++ b/test/js/samples/each-block-changed-check/expected-bundle.js @@ -63,10 +63,6 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -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; @@ -106,12 +102,11 @@ function init(component, options) { component._observers = { pre: blankObject(), post: blankObject() }; component._handlers = blankObject(); component._bind = options._bind; + component._differs = differs; component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; - var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; - component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { diff --git a/test/js/samples/event-handlers-custom/expected-bundle.js b/test/js/samples/event-handlers-custom/expected-bundle.js index dbda232f59..860d249ee0 100644 --- a/test/js/samples/event-handlers-custom/expected-bundle.js +++ b/test/js/samples/event-handlers-custom/expected-bundle.js @@ -43,10 +43,6 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -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; @@ -86,12 +82,11 @@ function init(component, options) { component._observers = { pre: blankObject(), post: blankObject() }; component._handlers = blankObject(); component._bind = options._bind; + component._differs = differs; component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; - var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; - component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { diff --git a/test/js/samples/head-no-whitespace/expected-bundle.js b/test/js/samples/head-no-whitespace/expected-bundle.js index c0ae2a8ba0..96d3b06cc8 100644 --- a/test/js/samples/head-no-whitespace/expected-bundle.js +++ b/test/js/samples/head-no-whitespace/expected-bundle.js @@ -43,10 +43,6 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -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; @@ -86,12 +82,11 @@ function init(component, options) { component._observers = { pre: blankObject(), post: blankObject() }; component._handlers = blankObject(); component._bind = options._bind; + component._differs = differs; component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; - var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; - component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { 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 31d618922e..29e8a05a8b 100644 --- a/test/js/samples/if-block-no-update/expected-bundle.js +++ b/test/js/samples/if-block-no-update/expected-bundle.js @@ -47,10 +47,6 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -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; @@ -90,12 +86,11 @@ function init(component, options) { component._observers = { pre: blankObject(), post: blankObject() }; component._handlers = blankObject(); component._bind = options._bind; + component._differs = differs; component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; - var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; - component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { diff --git a/test/js/samples/if-block-simple/expected-bundle.js b/test/js/samples/if-block-simple/expected-bundle.js index f36462efad..80a2a1475c 100644 --- a/test/js/samples/if-block-simple/expected-bundle.js +++ b/test/js/samples/if-block-simple/expected-bundle.js @@ -47,10 +47,6 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -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; @@ -90,12 +86,11 @@ function init(component, options) { component._observers = { pre: blankObject(), post: blankObject() }; component._handlers = blankObject(); component._bind = options._bind; + component._differs = differs; component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; - var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; - component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { 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 57402a155a..4348f9367e 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-multiple/expected-bundle.js @@ -47,10 +47,6 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -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; @@ -90,12 +86,11 @@ function init(component, options) { component._observers = { pre: blankObject(), post: blankObject() }; component._handlers = blankObject(); component._bind = options._bind; + component._differs = differs; component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; - var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; - component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { 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 069cc003b7..017dc960fc 100644 --- a/test/js/samples/inline-style-optimized-url/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-url/expected-bundle.js @@ -47,10 +47,6 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -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; @@ -90,12 +86,11 @@ function init(component, options) { component._observers = { pre: blankObject(), post: blankObject() }; component._handlers = blankObject(); component._bind = options._bind; + component._differs = differs; component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; - var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; - component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { diff --git a/test/js/samples/inline-style-optimized/expected-bundle.js b/test/js/samples/inline-style-optimized/expected-bundle.js index 643017655d..fc1ba783cc 100644 --- a/test/js/samples/inline-style-optimized/expected-bundle.js +++ b/test/js/samples/inline-style-optimized/expected-bundle.js @@ -47,10 +47,6 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -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; @@ -90,12 +86,11 @@ function init(component, options) { component._observers = { pre: blankObject(), post: blankObject() }; component._handlers = blankObject(); component._bind = options._bind; + component._differs = differs; component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; - var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; - component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { diff --git a/test/js/samples/inline-style-unoptimized/expected-bundle.js b/test/js/samples/inline-style-unoptimized/expected-bundle.js index 906bf21bb5..3958d3862b 100644 --- a/test/js/samples/inline-style-unoptimized/expected-bundle.js +++ b/test/js/samples/inline-style-unoptimized/expected-bundle.js @@ -47,10 +47,6 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -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; @@ -90,12 +86,11 @@ function init(component, options) { component._observers = { pre: blankObject(), post: blankObject() }; component._handlers = blankObject(); component._bind = options._bind; + component._differs = differs; component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; - var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; - component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { 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 a02405f10a..dbed2a12c0 100644 --- a/test/js/samples/input-without-blowback-guard/expected-bundle.js +++ b/test/js/samples/input-without-blowback-guard/expected-bundle.js @@ -51,10 +51,6 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -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; @@ -94,12 +90,11 @@ function init(component, options) { component._observers = { pre: blankObject(), post: blankObject() }; component._handlers = blankObject(); component._bind = options._bind; + component._differs = differs; component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; - var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; - component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { diff --git a/test/js/samples/legacy-input-type/expected-bundle.js b/test/js/samples/legacy-input-type/expected-bundle.js index b54727a24c..5b49b4995a 100644 --- a/test/js/samples/legacy-input-type/expected-bundle.js +++ b/test/js/samples/legacy-input-type/expected-bundle.js @@ -49,10 +49,6 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -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; @@ -92,12 +88,11 @@ function init(component, options) { component._observers = { pre: blankObject(), post: blankObject() }; component._handlers = blankObject(); component._bind = options._bind; + component._differs = differs; component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; - var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; - component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { diff --git a/test/js/samples/legacy-quote-class/expected-bundle.js b/test/js/samples/legacy-quote-class/expected-bundle.js index 3177f32f16..db13a962c9 100644 --- a/test/js/samples/legacy-quote-class/expected-bundle.js +++ b/test/js/samples/legacy-quote-class/expected-bundle.js @@ -66,10 +66,6 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -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; @@ -109,12 +105,11 @@ function init(component, options) { component._observers = { pre: blankObject(), post: blankObject() }; component._handlers = blankObject(); component._bind = options._bind; + component._differs = differs; component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; - var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; - component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { diff --git a/test/js/samples/media-bindings/expected-bundle.js b/test/js/samples/media-bindings/expected-bundle.js index 7a258f8965..230454d955 100644 --- a/test/js/samples/media-bindings/expected-bundle.js +++ b/test/js/samples/media-bindings/expected-bundle.js @@ -59,10 +59,6 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -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; @@ -102,12 +98,11 @@ function init(component, options) { component._observers = { pre: blankObject(), post: blankObject() }; component._handlers = blankObject(); component._bind = options._bind; + component._differs = differs; component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; - var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; - component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { diff --git a/test/js/samples/non-imported-component/expected-bundle.js b/test/js/samples/non-imported-component/expected-bundle.js index 2799a85ebe..b037ff3ad4 100644 --- a/test/js/samples/non-imported-component/expected-bundle.js +++ b/test/js/samples/non-imported-component/expected-bundle.js @@ -45,10 +45,6 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -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; @@ -88,12 +84,11 @@ function init(component, options) { component._observers = { pre: blankObject(), post: blankObject() }; component._handlers = blankObject(); component._bind = options._bind; + component._differs = differs; component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; - var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; - component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { diff --git a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js index 049ba0d86a..c0d41a7c76 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js @@ -31,10 +31,6 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -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; @@ -74,12 +70,11 @@ function init(component, options) { component._observers = { pre: blankObject(), post: blankObject() }; component._handlers = blankObject(); component._bind = options._bind; + component._differs = differs; component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; - var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; - component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { diff --git a/test/js/samples/setup-method/expected-bundle.js b/test/js/samples/setup-method/expected-bundle.js index 388bb495bc..d1b04e43a5 100644 --- a/test/js/samples/setup-method/expected-bundle.js +++ b/test/js/samples/setup-method/expected-bundle.js @@ -31,10 +31,6 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -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; @@ -74,12 +70,11 @@ function init(component, options) { component._observers = { pre: blankObject(), post: blankObject() }; component._handlers = blankObject(); component._bind = options._bind; + component._differs = differs; component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; - var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; - component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { diff --git a/test/js/samples/svg-title/expected-bundle.js b/test/js/samples/svg-title/expected-bundle.js index 46880a584c..21f8467d3b 100644 --- a/test/js/samples/svg-title/expected-bundle.js +++ b/test/js/samples/svg-title/expected-bundle.js @@ -51,10 +51,6 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -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; @@ -94,12 +90,11 @@ function init(component, options) { component._observers = { pre: blankObject(), post: blankObject() }; component._handlers = blankObject(); component._bind = options._bind; + component._differs = differs; component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; - var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; - component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { diff --git a/test/js/samples/title/expected-bundle.js b/test/js/samples/title/expected-bundle.js index 4e70625f70..bebf5e4466 100644 --- a/test/js/samples/title/expected-bundle.js +++ b/test/js/samples/title/expected-bundle.js @@ -31,10 +31,6 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -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; @@ -74,12 +70,11 @@ function init(component, options) { component._observers = { pre: blankObject(), post: blankObject() }; component._handlers = blankObject(); component._bind = options._bind; + component._differs = differs; component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; - var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; - component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { 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 2045954b41..f7302d8bd7 100644 --- a/test/js/samples/use-elements-as-anchors/expected-bundle.js +++ b/test/js/samples/use-elements-as-anchors/expected-bundle.js @@ -55,10 +55,6 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -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; @@ -98,12 +94,11 @@ function init(component, options) { component._observers = { pre: blankObject(), post: blankObject() }; component._handlers = blankObject(); component._bind = options._bind; + component._differs = differs; component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; - var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; - component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { diff --git a/test/js/samples/window-binding-scroll/expected-bundle.js b/test/js/samples/window-binding-scroll/expected-bundle.js index b0014988b7..f522e5f96d 100644 --- a/test/js/samples/window-binding-scroll/expected-bundle.js +++ b/test/js/samples/window-binding-scroll/expected-bundle.js @@ -51,10 +51,6 @@ function differs(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -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; @@ -94,12 +90,11 @@ function init(component, options) { component._observers = { pre: blankObject(), post: blankObject() }; component._handlers = blankObject(); component._bind = options._bind; + component._differs = differs; component.options = options; component.root = options.root || component; component.store = component.root.store || options.store; - var immutable = options.immutable !== undefined ? options.immutable : component.root.options.immutable; - component._differs = immutable ? differsImmutable : differs; } function observe(key, callback, options) { From 046a8000e68eb2459bd52bd59c3460972d6f732d Mon Sep 17 00:00:00 2001 From: Jacob Wright Date: Sun, 11 Feb 2018 00:03:04 -0700 Subject: [PATCH 5/6] Add another test --- .../component-static-immutable2/_config.js | 5 + .../expected-bundle.js | 236 ++++++++++++++++++ .../component-static-immutable2/expected.js | 62 +++++ .../component-static-immutable2/input.html | 9 + 4 files changed, 312 insertions(+) create mode 100644 test/js/samples/component-static-immutable2/_config.js create mode 100644 test/js/samples/component-static-immutable2/expected-bundle.js create mode 100644 test/js/samples/component-static-immutable2/expected.js create mode 100644 test/js/samples/component-static-immutable2/input.html diff --git a/test/js/samples/component-static-immutable2/_config.js b/test/js/samples/component-static-immutable2/_config.js new file mode 100644 index 0000000000..06713941e0 --- /dev/null +++ b/test/js/samples/component-static-immutable2/_config.js @@ -0,0 +1,5 @@ +export default { + options: { + immutable: true + } +}; \ No newline at end of file diff --git a/test/js/samples/component-static-immutable2/expected-bundle.js b/test/js/samples/component-static-immutable2/expected-bundle.js new file mode 100644 index 0000000000..abab18060b --- /dev/null +++ b/test/js/samples/component-static-immutable2/expected-bundle.js @@ -0,0 +1,236 @@ +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 differs(a, b) { + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); +} + +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._differs = differs; + + 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 */ +var Nested = window.Nested; + +function create_main_fragment(state, component) { + + var nested = new Nested({ + root: component.root, + data: { foo: "bar" } + }); + + return { + c: function create() { + nested._fragment.c(); + }, + + m: function mount(target, anchor) { + nested._mount(target, anchor); + }, + + p: noop, + + u: function unmount() { + nested._unmount(); + }, + + d: function destroy$$1() { + nested.destroy(false); + } + }; +} + +function SvelteComponent(options) { + init(this, options); + if (options.immutable !== undefined ? options.immutable : this.root.options.immutable) { + this._differs = differsImmutable; + } + this._state = assign({}, options.data); + + if (!options.root) { + this._oncreate = []; + this._beforecreate = []; + this._aftercreate = []; + } + + this._fragment = create_main_fragment(this._state, this); + + if (options.target) { + this._fragment.c(); + this._fragment.m(options.target, options.anchor || null); + + this._lock = true; + callAll(this._beforecreate); + callAll(this._oncreate); + callAll(this._aftercreate); + this._lock = false; + } +} + +assign(SvelteComponent.prototype, proto); + +export default SvelteComponent; diff --git a/test/js/samples/component-static-immutable2/expected.js b/test/js/samples/component-static-immutable2/expected.js new file mode 100644 index 0000000000..96dcb16874 --- /dev/null +++ b/test/js/samples/component-static-immutable2/expected.js @@ -0,0 +1,62 @@ +/* generated by Svelte vX.Y.Z */ +import { assign, callAll, differsImmutable, init, noop, proto } from "svelte/shared.js"; + +var Nested = window.Nested; + +function create_main_fragment(state, component) { + + var nested = new Nested({ + root: component.root, + data: { foo: "bar" } + }); + + return { + c: function create() { + nested._fragment.c(); + }, + + m: function mount(target, anchor) { + nested._mount(target, anchor); + }, + + p: noop, + + u: function unmount() { + nested._unmount(); + }, + + d: function destroy() { + nested.destroy(false); + } + }; +} + +function SvelteComponent(options) { + init(this, options); + if (options.immutable !== undefined ? options.immutable : this.root.options.immutable) { + this._differs = differsImmutable; + } + this._state = assign({}, options.data); + + if (!options.root) { + this._oncreate = []; + this._beforecreate = []; + this._aftercreate = []; + } + + this._fragment = create_main_fragment(this._state, this); + + if (options.target) { + this._fragment.c(); + this._fragment.m(options.target, options.anchor || null); + + this._lock = true; + callAll(this._beforecreate); + callAll(this._oncreate); + callAll(this._aftercreate); + this._lock = false; + } +} + +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/component-static-immutable2/input.html b/test/js/samples/component-static-immutable2/input.html new file mode 100644 index 0000000000..44a2bf2bc1 --- /dev/null +++ b/test/js/samples/component-static-immutable2/input.html @@ -0,0 +1,9 @@ + + + \ No newline at end of file From cb446bca64b49eba80ef8cb18f61eaf62948f6c5 Mon Sep 17 00:00:00 2001 From: Jacob Wright Date: Sun, 11 Feb 2018 01:10:13 -0700 Subject: [PATCH 6/6] Adds some runtime tests for the immutable option --- test/runtime/index.js | 4 +++- .../samples/immutable-mutable/Nested.html | 13 +++++++++++++ .../runtime/samples/immutable-mutable/_config.js | 16 ++++++++++++++++ test/runtime/samples/immutable-mutable/main.html | 13 +++++++++++++ .../runtime/samples/immutable-nested/Nested.html | 12 ++++++++++++ test/runtime/samples/immutable-nested/_config.js | 16 ++++++++++++++++ test/runtime/samples/immutable-nested/main.html | 13 +++++++++++++ test/runtime/samples/immutable-root/_config.js | 15 +++++++++++++++ test/runtime/samples/immutable-root/main.html | 14 ++++++++++++++ 9 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/immutable-mutable/Nested.html create mode 100644 test/runtime/samples/immutable-mutable/_config.js create mode 100644 test/runtime/samples/immutable-mutable/main.html create mode 100644 test/runtime/samples/immutable-nested/Nested.html create mode 100644 test/runtime/samples/immutable-nested/_config.js create mode 100644 test/runtime/samples/immutable-nested/main.html create mode 100644 test/runtime/samples/immutable-root/_config.js create mode 100644 test/runtime/samples/immutable-root/main.html diff --git a/test/runtime/index.js b/test/runtime/index.js index 778f47c0cc..8ec4c5194a 100644 --- a/test/runtime/index.js +++ b/test/runtime/index.js @@ -66,6 +66,7 @@ describe("runtime", () => { compileOptions.hydratable = hydrate; compileOptions.dev = config.dev; compileOptions.store = !!config.store; + compileOptions.immutable = config.immutable; // check that no ES2015+ syntax slipped in if (!config.allowES2015) { @@ -160,7 +161,8 @@ describe("runtime", () => { target, hydrate, data: config.data, - store: (config.store !== true && config.store) + store: (config.store !== true && config.store), + immutable: config.immutable }, config.options || {}); const component = new SvelteComponent(options); diff --git a/test/runtime/samples/immutable-mutable/Nested.html b/test/runtime/samples/immutable-mutable/Nested.html new file mode 100644 index 0000000000..02278e385e --- /dev/null +++ b/test/runtime/samples/immutable-mutable/Nested.html @@ -0,0 +1,13 @@ +

Called {{count}} times.

+ + \ No newline at end of file diff --git a/test/runtime/samples/immutable-mutable/_config.js b/test/runtime/samples/immutable-mutable/_config.js new file mode 100644 index 0000000000..5dab0f239b --- /dev/null +++ b/test/runtime/samples/immutable-mutable/_config.js @@ -0,0 +1,16 @@ +export default { + immutable: true, + html: `

Called 0 times.

`, + + test(assert, component, target, window) { + var nested = component.refs.nested; + nested.observe('foo', foo => { + nested.set({ count: nested.get('count') + 1 }); + }); + + assert.htmlEqual(target.innerHTML, `

Called 1 times.

`); + + nested.set({ foo: nested.get('foo') }); + assert.htmlEqual(target.innerHTML, `

Called 2 times.

`); + } +}; diff --git a/test/runtime/samples/immutable-mutable/main.html b/test/runtime/samples/immutable-mutable/main.html new file mode 100644 index 0000000000..4e36143361 --- /dev/null +++ b/test/runtime/samples/immutable-mutable/main.html @@ -0,0 +1,13 @@ +
+ +
+ + diff --git a/test/runtime/samples/immutable-nested/Nested.html b/test/runtime/samples/immutable-nested/Nested.html new file mode 100644 index 0000000000..05eb9f3fdf --- /dev/null +++ b/test/runtime/samples/immutable-nested/Nested.html @@ -0,0 +1,12 @@ +

Called {{count}} times.

+ + \ No newline at end of file diff --git a/test/runtime/samples/immutable-nested/_config.js b/test/runtime/samples/immutable-nested/_config.js new file mode 100644 index 0000000000..541566ce4d --- /dev/null +++ b/test/runtime/samples/immutable-nested/_config.js @@ -0,0 +1,16 @@ +export default { + immutable: true, + html: `

Called 0 times.

`, + + test(assert, component, target, window) { + var nested = component.refs.nested; + nested.observe('foo', foo => { + nested.set({ count: nested.get('count') + 1 }); + }); + + assert.htmlEqual(target.innerHTML, `

Called 1 times.

`); + + nested.set({ foo: nested.get('foo') }); + assert.htmlEqual(target.innerHTML, `

Called 1 times.

`); + } +}; diff --git a/test/runtime/samples/immutable-nested/main.html b/test/runtime/samples/immutable-nested/main.html new file mode 100644 index 0000000000..4e36143361 --- /dev/null +++ b/test/runtime/samples/immutable-nested/main.html @@ -0,0 +1,13 @@ +
+ +
+ + diff --git a/test/runtime/samples/immutable-root/_config.js b/test/runtime/samples/immutable-root/_config.js new file mode 100644 index 0000000000..a862008d7d --- /dev/null +++ b/test/runtime/samples/immutable-root/_config.js @@ -0,0 +1,15 @@ +export default { + immutable: true, + html: `

Called 0 times.

`, + + test(assert, component, target, window) { + component.observe('foo', foo => { + component.set({ count: component.get('count') + 1 }); + }); + + assert.htmlEqual(target.innerHTML, `

Called 1 times.

`); + + component.set({ foo: component.get('foo') }); + assert.htmlEqual(target.innerHTML, `

Called 1 times.

`); + } +}; diff --git a/test/runtime/samples/immutable-root/main.html b/test/runtime/samples/immutable-root/main.html new file mode 100644 index 0000000000..087f561caf --- /dev/null +++ b/test/runtime/samples/immutable-root/main.html @@ -0,0 +1,14 @@ +
+

Called {{count}} times.

+
+ + \ No newline at end of file