correctly report changed properties in initial state/update events - fixes #1356

pull/1364/head
Rich Harris 7 years ago
parent 0bc68286d5
commit 991bd9dce8

@ -218,16 +218,6 @@ export default function dom(
`if (!document.getElementById("${generator.stylesheet.id}-style")) @add_css();`)
}
${hasInitHooks && deindent`
var self = this;
var _oncreate = function() {
var changed = { ${expectedProperties.map(p => `${p}: 1`).join(', ')} };
${templateProperties.onstate && `%onstate.call(self, { changed: changed, current: self._state });`}
${templateProperties.oncreate && `%oncreate.call(self);`}
self.fire("update", { changed: changed, current: self._state });
};
`}
${(hasInitHooks || generator.hasComponents || generator.hasComplexBindings || generator.hasIntroTransitions) && deindent`
if (!options.root) {
this._oncreate = [];
@ -241,7 +231,11 @@ export default function dom(
this._fragment = @create_main_fragment(this, this._state);
${hasInitHooks && deindent`
this.root._oncreate.push(_oncreate);
this.root._oncreate.push(() => {
${templateProperties.onstate && `%onstate.call(this, { changed: @makePropertyMap(this._state), current: this._state });`}
${templateProperties.oncreate && `%oncreate.call(this);`}
this.fire("update", { changed: @makePropertyMap(this._state), current: this._state });
});
`}
${generator.customElement ? deindent`

@ -4,3 +4,11 @@ export function assign(tar, src) {
for (var k in src) tar[k] = src[k];
return tar;
}
export function makePropertyMap(obj) {
const map = {};
for (const key in obj) {
map[key] = 1;
}
return map;
}

@ -5,6 +5,14 @@ function assign(tar, src) {
return tar;
}
function makePropertyMap(obj) {
const map = {};
for (const key in obj) {
map[key] = 1;
}
return map;
}
function blankObject() {
return Object.create(null);
}
@ -150,20 +158,16 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign(data_1(), options.data);
var self = this;
var _oncreate = function() {
var changed = { };
oncreate.call(self);
self.fire("update", { changed: changed, current: self._state });
};
if (!options.root) {
this._oncreate = [];
}
this._fragment = create_main_fragment(this, this._state);
this.root._oncreate.push(_oncreate);
this.root._oncreate.push(() => {
oncreate.call(this);
this.fire("update", { changed: makePropertyMap(this._state), current: this._state });
});
if (options.target) {
this._fragment.c();

@ -1,5 +1,5 @@
/* generated by Svelte vX.Y.Z */
import { assign, callAll, init, noop, proto } from "svelte/shared.js";
import { assign, callAll, init, makePropertyMap, noop, proto } from "svelte/shared.js";
function data_1() {
return {
@ -30,20 +30,16 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign(data_1(), options.data);
var self = this;
var _oncreate = function() {
var changed = { };
oncreate.call(self);
self.fire("update", { changed: changed, current: self._state });
};
if (!options.root) {
this._oncreate = [];
}
this._fragment = create_main_fragment(this, this._state);
this.root._oncreate.push(_oncreate);
this.root._oncreate.push(() => {
oncreate.call(this);
this.fire("update", { changed: makePropertyMap(this._state), current: this._state });
});
if (options.target) {
this._fragment.c();

@ -1,7 +1,7 @@
<script>
export default {
onstate({ changed }) {
this.changed = changed;
this.changed = changed;
}
};
</script>

Loading…
Cancel
Save