From cb8071acd456e916b46bb42916383f3f0a8a0c4e Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 24 Feb 2018 13:08:28 -0500 Subject: [PATCH] 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