From 8643b7ac887f465fdaa34561e6cb706381fb8ddf Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 22 Apr 2018 10:47:37 -0400 Subject: [PATCH] tweak --- src/generators/dom/index.ts | 4 ++-- src/shared/utils.js | 9 +++------ test/js/samples/deconflict-globals/expected-bundle.js | 11 ++++------- test/js/samples/deconflict-globals/expected.js | 4 ++-- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts index 0a4b48b92f..337d23d2ed 100644 --- a/src/generators/dom/index.ts +++ b/src/generators/dom/index.ts @@ -232,9 +232,9 @@ export default function dom( ${hasInitHooks && deindent` this.root._oncreate.push(() => { - ${templateProperties.onstate && `%onstate.call(this, { changed: @makePropertyMap(this._state), current: this._state });`} + ${templateProperties.onstate && `%onstate.call(this, { changed: @assignTrue({}, this._state), current: this._state });`} ${templateProperties.oncreate && `%oncreate.call(this);`} - this.fire("update", { changed: @makePropertyMap(this._state), current: this._state }); + this.fire("update", { changed: @assignTrue({}, this._state), current: this._state }); }); `} diff --git a/src/shared/utils.js b/src/shared/utils.js index be01c7a131..45260d49bc 100644 --- a/src/shared/utils.js +++ b/src/shared/utils.js @@ -5,10 +5,7 @@ export function assign(tar, src) { return tar; } -export function makePropertyMap(obj) { - const map = {}; - for (const key in obj) { - map[key] = 1; - } - return map; +export function assignTrue(tar, src) { + for (var k in src) tar[k] = 1; + return tar; } \ No newline at end of file diff --git a/test/js/samples/deconflict-globals/expected-bundle.js b/test/js/samples/deconflict-globals/expected-bundle.js index 09143c55bc..ab0773f324 100644 --- a/test/js/samples/deconflict-globals/expected-bundle.js +++ b/test/js/samples/deconflict-globals/expected-bundle.js @@ -5,12 +5,9 @@ function assign(tar, src) { return tar; } -function makePropertyMap(obj) { - const map = {}; - for (const key in obj) { - map[key] = 1; - } - return map; +function assignTrue(tar, src) { + for (var k in src) tar[k] = 1; + return tar; } function blankObject() { @@ -166,7 +163,7 @@ function SvelteComponent(options) { this.root._oncreate.push(() => { oncreate.call(this); - this.fire("update", { changed: makePropertyMap(this._state), current: this._state }); + this.fire("update", { changed: assignTrue({}, this._state), current: this._state }); }); if (options.target) { diff --git a/test/js/samples/deconflict-globals/expected.js b/test/js/samples/deconflict-globals/expected.js index b4b7633dcb..8b91d1550a 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, makePropertyMap, noop, proto } from "svelte/shared.js"; +import { assign, assignTrue, callAll, init, noop, proto } from "svelte/shared.js"; function data_1() { return { @@ -38,7 +38,7 @@ function SvelteComponent(options) { this.root._oncreate.push(() => { oncreate.call(this); - this.fire("update", { changed: makePropertyMap(this._state), current: this._state }); + this.fire("update", { changed: assignTrue({}, this._state), current: this._state }); }); if (options.target) {