From d625e8d16fc4eb8bd93a059e2caaac97213f05c0 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 24 Feb 2018 13:08:28 -0500 Subject: [PATCH 1/2] allow observing $foo in dev mode - #1181 --- src/shared/index.js | 2 +- .../samples/store-observe-dollar/_config.js | 25 +++++++++++++++++++ .../samples/store-observe-dollar/main.html | 1 + 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/store-observe-dollar/_config.js create mode 100644 test/runtime/samples/store-observe-dollar/main.html diff --git a/src/shared/index.js b/src/shared/index.js index cf953e4bf1..d9d6475e64 100644 --- a/src/shared/index.js +++ b/src/shared/index.js @@ -100,7 +100,7 @@ export function observe(key, callback, options) { } export function observeDev(key, callback, options) { - var c = (key = '' + key).search(/[^\w]/); + var c = (key = '' + key).search(/[.[]/); if (c > -1) { var message = 'The first argument to component.observe(...) must be the name of a top-level property'; diff --git a/test/runtime/samples/store-observe-dollar/_config.js b/test/runtime/samples/store-observe-dollar/_config.js new file mode 100644 index 0000000000..1861b937d9 --- /dev/null +++ b/test/runtime/samples/store-observe-dollar/_config.js @@ -0,0 +1,25 @@ +import { Store } from '../../../../store.js'; + +const store = new Store({ + name: 'world' +}); + +export default { + store, + + html: `

Hello world!

`, + + dev: true, + + test(assert, component) { + const names = []; + + component.observe('$name', name => { + names.push(name); + }); + + store.set({ name: 'everybody' }); + + assert.deepEqual(names, ['world', 'everybody']); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/store-observe-dollar/main.html b/test/runtime/samples/store-observe-dollar/main.html new file mode 100644 index 0000000000..28154934b8 --- /dev/null +++ b/test/runtime/samples/store-observe-dollar/main.html @@ -0,0 +1 @@ +

Hello {{$name}}!

\ No newline at end of file From e561f05e9f3cd43a70e9a68ee76a9e82b268d6a4 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 24 Feb 2018 13:25:27 -0500 Subject: [PATCH 2/2] fix out of date test --- test/js/samples/legacy-default/expected-bundle.js | 4 ++-- test/js/samples/legacy-default/expected.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/js/samples/legacy-default/expected-bundle.js b/test/js/samples/legacy-default/expected-bundle.js index f2fa173262..023ac9b1bc 100644 --- a/test/js/samples/legacy-default/expected-bundle.js +++ b/test/js/samples/legacy-default/expected-bundle.js @@ -204,7 +204,7 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ -function create_main_fragment(state, component) { +function create_main_fragment(component, state) { var text, p, text_1, text_2, text_3, slot_content_default = component._slotted["default"], slot_content_default_before, slot_content_default_after; var foo = new Foo({ @@ -270,7 +270,7 @@ function SvelteComponent(options) { this.slots = {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this, this._state); if (options.target) { this._fragment.c(); diff --git a/test/js/samples/legacy-default/expected.js b/test/js/samples/legacy-default/expected.js index 27cdd1896f..6c90bb8f13 100644 --- a/test/js/samples/legacy-default/expected.js +++ b/test/js/samples/legacy-default/expected.js @@ -1,7 +1,7 @@ /* generated by Svelte vX.Y.Z */ import { appendNode, assign, callAll, createComment, createElement, createFragment, createText, detachNode, init, insertNode, noop, proto, reinsertBetween } from "svelte/shared.js"; -function create_main_fragment(state, component) { +function create_main_fragment(component, state) { var text, p, text_1, text_2, text_3, slot_content_default = component._slotted["default"], slot_content_default_before, slot_content_default_after; var foo = new Foo({ @@ -67,7 +67,7 @@ function SvelteComponent(options) { this.slots = {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this, this._state); if (options.target) { this._fragment.c();