Merge branch 'master' into gh-1122

pull/1173/head
Rich Harris 7 years ago
commit d162ce9968

@ -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;`;
@ -174,7 +174,7 @@ export default function dom(
? `@proto`
: deindent`
{
${['destroy', 'get', 'fire', 'observe', 'on', 'set', 'teardown', '_set', '_mount', '_unmount']
${['destroy', 'get', 'fire', 'observe', 'on', 'set', 'teardown', '_set', '_mount', '_unmount', '_differs']
.map(n => `${n}: @${n === 'teardown' ? 'destroy' : n}`)
.join(',\n')}
}`;
@ -360,6 +360,8 @@ export default function dom(
`);
}
const immutable = templateProperties.immutable ? templateProperties.immutable.value.value : options.immutable;
builder.addBlock(deindent`
${options.dev && deindent`
${name}.prototype._checkReadOnly = function _checkReadOnly(newState) {
@ -379,6 +381,8 @@ export default function dom(
${templateProperties.setup && `%setup(${name});`}
${templateProperties.preload && `${name}.preload = %preload;`}
${immutable && `${name}.prototype._differs = @_differsImmutable;`}
`);
const usedHelpers = new Set();

@ -52,6 +52,7 @@ export interface CompileOptions {
cssOutputFilename?: string;
dev?: boolean;
immutable?: boolean;
shared?: boolean | string;
cascade?: boolean;
hydratable?: boolean;

@ -25,8 +25,12 @@ export function destroyDev(detach) {
};
}
export function differs(a, b) {
return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
export function _differs(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
export function _differsImmutable(a, b) {
return a != a ? b == b : a !== b;
}
export function dispatchObservers(component, group, changed, newState, oldState) {
@ -150,7 +154,7 @@ export 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;
@ -211,7 +215,8 @@ export var proto = {
_recompute: noop,
_set: _set,
_mount: _mount,
_unmount: _unmount
_unmount: _unmount,
_differs: _differs
};
export var protoDev = {
@ -225,5 +230,6 @@ export var protoDev = {
_recompute: noop,
_set: _set,
_mount: _mount,
_unmount: _unmount
_unmount: _unmount,
_differs: _differs
};

@ -0,0 +1,11 @@
import { Validator } from '../../';
import { Node } from '../../../interfaces';
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`,
prop.value.start
);
}
}

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

@ -1,13 +1,14 @@
import {
assign,
blankObject,
differs,
_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;

@ -51,8 +51,8 @@ function destroy(detach) {
this._fragment = this._state = null;
}
function differs(a, b) {
return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
function _differs(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function dispatchObservers(component, group, changed, newState, oldState) {
@ -151,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;
@ -189,7 +189,8 @@ var proto = {
_recompute: noop,
_set: _set,
_mount: _mount,
_unmount: _unmount
_unmount: _unmount,
_differs: _differs
};
/* generated by Svelte vX.Y.Z */

@ -0,0 +1,5 @@
export default {
options: {
immutable: true
}
};

@ -0,0 +1,235 @@
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.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,
_differs: _differs
};
/* 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);
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);
SvelteComponent.prototype._differs = _differsImmutable;
export default SvelteComponent;

@ -0,0 +1,61 @@
/* generated by Svelte vX.Y.Z */
import { _differsImmutable, assign, callAll, 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);
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);
SvelteComponent.prototype._differs = _differsImmutable;
export default SvelteComponent;

@ -0,0 +1,10 @@
<Nested foo='bar'/>
<script>
export default {
immutable: true,
components: {
Nested: window.Nested
}
};
</script>

@ -0,0 +1,5 @@
export default {
options: {
immutable: true
}
};

@ -0,0 +1,235 @@
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.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,
_differs: _differs
};
/* 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);
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);
SvelteComponent.prototype._differs = _differsImmutable;
export default SvelteComponent;

@ -0,0 +1,61 @@
/* generated by Svelte vX.Y.Z */
import { _differsImmutable, assign, callAll, 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);
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);
SvelteComponent.prototype._differs = _differsImmutable;
export default SvelteComponent;

@ -0,0 +1,9 @@
<Nested foo='bar'/>
<script>
export default {
components: {
Nested: window.Nested
}
};
</script>

@ -27,8 +27,8 @@ function destroy(detach) {
this._fragment = this._state = null;
}
function differs(a, b) {
return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
function _differs(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function dispatchObservers(component, group, changed, newState, oldState) {
@ -127,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;
@ -165,7 +165,8 @@ var proto = {
_recompute: noop,
_set: _set,
_mount: _mount,
_unmount: _unmount
_unmount: _unmount,
_differs: _differs
};
/* generated by Svelte vX.Y.Z */

@ -27,8 +27,8 @@ function destroy(detach) {
this._fragment = this._state = null;
}
function differs(a, b) {
return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
function _differs(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function dispatchObservers(component, group, changed, newState, oldState) {
@ -127,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;
@ -165,7 +165,8 @@ var proto = {
_recompute: noop,
_set: _set,
_mount: _mount,
_unmount: _unmount
_unmount: _unmount,
_differs: _differs
};
/* generated by Svelte vX.Y.Z */
@ -209,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;
}
};

@ -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;
@ -41,8 +41,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;

@ -47,8 +47,8 @@ function destroy(detach) {
this._fragment = this._state = null;
}
function differs(a, b) {
return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
function _differs(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function dispatchObservers(component, group, changed, newState, oldState) {
@ -147,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;
@ -185,7 +185,8 @@ var proto = {
_recompute: noop,
_set: _set,
_mount: _mount,
_unmount: _unmount
_unmount: _unmount,
_differs: _differs
};
/* generated by Svelte vX.Y.Z */

@ -39,8 +39,8 @@ function destroy(detach) {
this._fragment = this._state = null;
}
function differs(a, b) {
return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
function _differs(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function dispatchObservers(component, group, changed, newState, oldState) {
@ -139,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;
@ -177,7 +177,8 @@ var proto = {
_recompute: noop,
_set: _set,
_mount: _mount,
_unmount: _unmount
_unmount: _unmount,
_differs: _differs
};
/* generated by Svelte vX.Y.Z */

@ -27,8 +27,8 @@ function destroy(detach) {
this._fragment = this._state = null;
}
function differs(a, b) {
return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
function _differs(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function dispatchObservers(component, group, changed, newState, oldState) {
@ -127,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;
@ -165,7 +165,8 @@ var proto = {
_recompute: noop,
_set: _set,
_mount: _mount,
_unmount: _unmount
_unmount: _unmount,
_differs: _differs
};
/* generated by Svelte vX.Y.Z */

@ -43,8 +43,8 @@ function destroy(detach) {
this._fragment = this._state = null;
}
function differs(a, b) {
return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
function _differs(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function dispatchObservers(component, group, changed, newState, oldState) {
@ -143,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;
@ -181,7 +181,8 @@ var proto = {
_recompute: noop,
_set: _set,
_mount: _mount,
_unmount: _unmount
_unmount: _unmount,
_differs: _differs
};
/* generated by Svelte vX.Y.Z */

@ -47,8 +47,8 @@ function destroy(detach) {
this._fragment = this._state = null;
}
function differs(a, b) {
return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
function _differs(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function dispatchObservers(component, group, changed, newState, oldState) {
@ -147,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;
@ -185,7 +185,8 @@ var proto = {
_recompute: noop,
_set: _set,
_mount: _mount,
_unmount: _unmount
_unmount: _unmount,
_differs: _differs
};
/* generated by Svelte vX.Y.Z */

@ -47,8 +47,8 @@ function destroy(detach) {
this._fragment = this._state = null;
}
function differs(a, b) {
return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
function _differs(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function dispatchObservers(component, group, changed, newState, oldState) {
@ -147,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;
@ -185,7 +185,8 @@ var proto = {
_recompute: noop,
_set: _set,
_mount: _mount,
_unmount: _unmount
_unmount: _unmount,
_differs: _differs
};
/* generated by Svelte vX.Y.Z */

@ -59,8 +59,8 @@ function destroy(detach) {
this._fragment = this._state = null;
}
function differs(a, b) {
return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
function _differs(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function dispatchObservers(component, group, changed, newState, oldState) {
@ -159,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;
@ -197,7 +197,8 @@ var proto = {
_recompute: noop,
_set: _set,
_mount: _mount,
_unmount: _unmount
_unmount: _unmount,
_differs: _differs
};
/* generated by Svelte vX.Y.Z */

@ -39,8 +39,8 @@ function destroy(detach) {
this._fragment = this._state = null;
}
function differs(a, b) {
return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
function _differs(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function dispatchObservers(component, group, changed, newState, oldState) {
@ -139,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;
@ -177,7 +177,8 @@ var proto = {
_recompute: noop,
_set: _set,
_mount: _mount,
_unmount: _unmount
_unmount: _unmount,
_differs: _differs
};
/* generated by Svelte vX.Y.Z */

@ -39,8 +39,8 @@ function destroy(detach) {
this._fragment = this._state = null;
}
function differs(a, b) {
return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
function _differs(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function dispatchObservers(component, group, changed, newState, oldState) {
@ -139,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;
@ -177,7 +177,8 @@ var proto = {
_recompute: noop,
_set: _set,
_mount: _mount,
_unmount: _unmount
_unmount: _unmount,
_differs: _differs
};
/* generated by Svelte vX.Y.Z */

@ -43,8 +43,8 @@ function destroy(detach) {
this._fragment = this._state = null;
}
function differs(a, b) {
return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
function _differs(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function dispatchObservers(component, group, changed, newState, oldState) {
@ -143,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;
@ -181,7 +181,8 @@ var proto = {
_recompute: noop,
_set: _set,
_mount: _mount,
_unmount: _unmount
_unmount: _unmount,
_differs: _differs
};
/* generated by Svelte vX.Y.Z */

@ -43,8 +43,8 @@ function destroy(detach) {
this._fragment = this._state = null;
}
function differs(a, b) {
return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
function _differs(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function dispatchObservers(component, group, changed, newState, oldState) {
@ -143,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;
@ -181,7 +181,8 @@ var proto = {
_recompute: noop,
_set: _set,
_mount: _mount,
_unmount: _unmount
_unmount: _unmount,
_differs: _differs
};
/* generated by Svelte vX.Y.Z */

@ -43,8 +43,8 @@ function destroy(detach) {
this._fragment = this._state = null;
}
function differs(a, b) {
return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
function _differs(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function dispatchObservers(component, group, changed, newState, oldState) {
@ -143,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;
@ -181,7 +181,8 @@ var proto = {
_recompute: noop,
_set: _set,
_mount: _mount,
_unmount: _unmount
_unmount: _unmount,
_differs: _differs
};
/* generated by Svelte vX.Y.Z */

@ -43,8 +43,8 @@ function destroy(detach) {
this._fragment = this._state = null;
}
function differs(a, b) {
return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
function _differs(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function dispatchObservers(component, group, changed, newState, oldState) {
@ -143,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;
@ -181,7 +181,8 @@ var proto = {
_recompute: noop,
_set: _set,
_mount: _mount,
_unmount: _unmount
_unmount: _unmount,
_differs: _differs
};
/* generated by Svelte vX.Y.Z */

@ -43,8 +43,8 @@ function destroy(detach) {
this._fragment = this._state = null;
}
function differs(a, b) {
return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
function _differs(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function dispatchObservers(component, group, changed, newState, oldState) {
@ -143,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;
@ -181,7 +181,8 @@ var proto = {
_recompute: noop,
_set: _set,
_mount: _mount,
_unmount: _unmount
_unmount: _unmount,
_differs: _differs
};
/* generated by Svelte vX.Y.Z */

@ -43,8 +43,8 @@ function destroy(detach) {
this._fragment = this._state = null;
}
function differs(a, b) {
return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
function _differs(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function dispatchObservers(component, group, changed, newState, oldState) {
@ -143,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;
@ -181,7 +181,8 @@ var proto = {
_recompute: noop,
_set: _set,
_mount: _mount,
_unmount: _unmount
_unmount: _unmount,
_differs: _differs
};
/* generated by Svelte vX.Y.Z */

@ -47,8 +47,8 @@ function destroy(detach) {
this._fragment = this._state = null;
}
function differs(a, b) {
return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
function _differs(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function dispatchObservers(component, group, changed, newState, oldState) {
@ -147,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;
@ -185,7 +185,8 @@ var proto = {
_recompute: noop,
_set: _set,
_mount: _mount,
_unmount: _unmount
_unmount: _unmount,
_differs: _differs
};
/* generated by Svelte vX.Y.Z */

@ -45,8 +45,8 @@ function destroy(detach) {
this._fragment = this._state = null;
}
function differs(a, b) {
return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
function _differs(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function dispatchObservers(component, group, changed, newState, oldState) {
@ -145,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;
@ -183,7 +183,8 @@ var proto = {
_recompute: noop,
_set: _set,
_mount: _mount,
_unmount: _unmount
_unmount: _unmount,
_differs: _differs
};
/* generated by Svelte vX.Y.Z */

@ -62,8 +62,8 @@ function destroy(detach) {
this._fragment = this._state = null;
}
function differs(a, b) {
return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
function _differs(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function dispatchObservers(component, group, changed, newState, oldState) {
@ -162,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;
@ -200,7 +200,8 @@ var proto = {
_recompute: noop,
_set: _set,
_mount: _mount,
_unmount: _unmount
_unmount: _unmount,
_differs: _differs
};
/* generated by Svelte vX.Y.Z */

@ -55,8 +55,8 @@ function destroy(detach) {
this._fragment = this._state = null;
}
function differs(a, b) {
return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
function _differs(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function dispatchObservers(component, group, changed, newState, oldState) {
@ -155,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;
@ -193,7 +193,8 @@ var proto = {
_recompute: noop,
_set: _set,
_mount: _mount,
_unmount: _unmount
_unmount: _unmount,
_differs: _differs
};
/* generated by Svelte vX.Y.Z */

@ -41,8 +41,8 @@ function destroy(detach) {
this._fragment = this._state = null;
}
function differs(a, b) {
return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
function _differs(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function dispatchObservers(component, group, changed, newState, oldState) {
@ -141,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;
@ -179,7 +179,8 @@ var proto = {
_recompute: noop,
_set: _set,
_mount: _mount,
_unmount: _unmount
_unmount: _unmount,
_differs: _differs
};
/* generated by Svelte vX.Y.Z */

@ -27,8 +27,8 @@ function destroy(detach) {
this._fragment = this._state = null;
}
function differs(a, b) {
return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
function _differs(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function dispatchObservers(component, group, changed, newState, oldState) {
@ -127,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;
@ -165,7 +165,8 @@ var proto = {
_recompute: noop,
_set: _set,
_mount: _mount,
_unmount: _unmount
_unmount: _unmount,
_differs: _differs
};
/* generated by Svelte vX.Y.Z */

@ -27,8 +27,8 @@ function destroy(detach) {
this._fragment = this._state = null;
}
function differs(a, b) {
return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
function _differs(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function dispatchObservers(component, group, changed, newState, oldState) {
@ -127,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;
@ -165,7 +165,8 @@ var proto = {
_recompute: noop,
_set: _set,
_mount: _mount,
_unmount: _unmount
_unmount: _unmount,
_differs: _differs
};
/* generated by Svelte vX.Y.Z */

@ -47,8 +47,8 @@ function destroy(detach) {
this._fragment = this._state = null;
}
function differs(a, b) {
return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
function _differs(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function dispatchObservers(component, group, changed, newState, oldState) {
@ -147,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;
@ -185,7 +185,8 @@ var proto = {
_recompute: noop,
_set: _set,
_mount: _mount,
_unmount: _unmount
_unmount: _unmount,
_differs: _differs
};
/* generated by Svelte vX.Y.Z */

@ -27,8 +27,8 @@ function destroy(detach) {
this._fragment = this._state = null;
}
function differs(a, b) {
return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
function _differs(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function dispatchObservers(component, group, changed, newState, oldState) {
@ -127,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;
@ -165,7 +165,8 @@ var proto = {
_recompute: noop,
_set: _set,
_mount: _mount,
_unmount: _unmount
_unmount: _unmount,
_differs: _differs
};
/* generated by Svelte vX.Y.Z */

@ -51,8 +51,8 @@ function destroy(detach) {
this._fragment = this._state = null;
}
function differs(a, b) {
return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
function _differs(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function dispatchObservers(component, group, changed, newState, oldState) {
@ -151,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;
@ -189,7 +189,8 @@ var proto = {
_recompute: noop,
_set: _set,
_mount: _mount,
_unmount: _unmount
_unmount: _unmount,
_differs: _differs
};
/* generated by Svelte vX.Y.Z */

@ -47,8 +47,8 @@ function destroy(detach) {
this._fragment = this._state = null;
}
function differs(a, b) {
return a !== b || ((a && typeof a === 'object') || typeof a === 'function');
function _differs(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function dispatchObservers(component, group, changed, newState, oldState) {
@ -147,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;
@ -185,7 +185,8 @@ var proto = {
_recompute: noop,
_set: _set,
_mount: _mount,
_unmount: _unmount
_unmount: _unmount,
_differs: _differs
};
/* generated by Svelte vX.Y.Z */

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

@ -0,0 +1,13 @@
<h3>Called {{count}} times.</h3>
<script>
export default {
immutable: false,
data() {
return {
count: 0,
foo: { bar: 'baz' }
};
}
}
</script>

@ -0,0 +1,16 @@
export default {
immutable: true,
html: `<div><h3>Called 0 times.</h3></div>`,
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, `<div><h3>Called 1 times.</h3></div>`);
nested.set({ foo: nested.get('foo') });
assert.htmlEqual(target.innerHTML, `<div><h3>Called 2 times.</h3></div>`);
}
};

@ -0,0 +1,13 @@
<div>
<Nested ref:nested />
</div>
<script>
import Nested from './Nested.html';
export default {
components: {
Nested
}
};
</script>

@ -0,0 +1,12 @@
<h3>Called {{count}} times.</h3>
<script>
export default {
data() {
return {
count: 0,
foo: { bar: 'baz' }
};
}
}
</script>

@ -0,0 +1,16 @@
export default {
immutable: true,
html: `<div><h3>Called 0 times.</h3></div>`,
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, `<div><h3>Called 1 times.</h3></div>`);
nested.set({ foo: nested.get('foo') });
assert.htmlEqual(target.innerHTML, `<div><h3>Called 1 times.</h3></div>`);
}
};

@ -0,0 +1,13 @@
<div>
<Nested ref:nested />
</div>
<script>
import Nested from './Nested.html';
export default {
components: {
Nested
}
};
</script>

@ -0,0 +1,15 @@
export default {
immutable: true,
html: `<div><h3>Called 0 times.</h3></div>`,
test(assert, component, target, window) {
component.observe('foo', foo => {
component.set({ count: component.get('count') + 1 });
});
assert.htmlEqual(target.innerHTML, `<div><h3>Called 1 times.</h3></div>`);
component.set({ foo: component.get('foo') });
assert.htmlEqual(target.innerHTML, `<div><h3>Called 1 times.</h3></div>`);
}
};

@ -0,0 +1,14 @@
<div>
<h3>Called {{count}} times.</h3>
</div>
<script>
export default {
data() {
return {
count: 0,
foo: { bar: 'baz' }
};
}
}
</script>

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

Loading…
Cancel
Save