mirror of
https://github.com/sveltejs/svelte.git
synced 2024-12-01 17:30:59 +01:00
Merge pull request #1364 from sveltejs/gh-1356
Report initial `changed` based on state, not expected properties
This commit is contained in:
commit
6534fef37d
@ -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: @assignTrue({}, this._state), current: this._state });`}
|
||||
${templateProperties.oncreate && `%oncreate.call(this);`}
|
||||
this.fire("update", { changed: @assignTrue({}, this._state), current: this._state });
|
||||
});
|
||||
`}
|
||||
|
||||
${generator.customElement ? deindent`
|
||||
|
@ -4,3 +4,8 @@ export function assign(tar, src) {
|
||||
for (var k in src) tar[k] = src[k];
|
||||
return tar;
|
||||
}
|
||||
|
||||
export function assignTrue(tar, src) {
|
||||
for (var k in src) tar[k] = 1;
|
||||
return tar;
|
||||
}
|
@ -5,6 +5,11 @@ function assign(tar, src) {
|
||||
return tar;
|
||||
}
|
||||
|
||||
function assignTrue(tar, src) {
|
||||
for (var k in src) tar[k] = 1;
|
||||
return tar;
|
||||
}
|
||||
|
||||
function blankObject() {
|
||||
return Object.create(null);
|
||||
}
|
||||
@ -151,20 +156,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: assignTrue({}, 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, assignTrue, callAll, init, 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: assignTrue({}, this._state), current: this._state });
|
||||
});
|
||||
|
||||
if (options.target) {
|
||||
this._fragment.c();
|
||||
|
11
test/runtime/samples/onstate-no-template/_config.js
Normal file
11
test/runtime/samples/onstate-no-template/_config.js
Normal file
@ -0,0 +1,11 @@
|
||||
export default {
|
||||
'skip-ssr': true,
|
||||
|
||||
data: {
|
||||
foo: 'woo!'
|
||||
},
|
||||
|
||||
test(assert, component) {
|
||||
assert.deepEqual(component.changed, { foo: 1 });
|
||||
}
|
||||
};
|
7
test/runtime/samples/onstate-no-template/main.html
Normal file
7
test/runtime/samples/onstate-no-template/main.html
Normal file
@ -0,0 +1,7 @@
|
||||
<script>
|
||||
export default {
|
||||
onstate({ changed }) {
|
||||
this.changed = changed;
|
||||
}
|
||||
};
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user