Skip to content

Commit

Permalink
allow observing $foo in dev mode - #1181
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Feb 24, 2018
1 parent 805c72f commit cb8071a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/shared/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
25 changes: 25 additions & 0 deletions test/runtime/samples/store-observe-dollar/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Store } from '../../../../store.js';

const store = new Store({
name: 'world'
});

export default {
store,

html: `<h1>Hello world!</h1>`,

dev: true,

test(assert, component) {
const names = [];

component.observe('$name', name => {
names.push(name);
});

store.set({ name: 'everybody' });

assert.deepEqual(names, ['world', 'everybody']);
}
};
1 change: 1 addition & 0 deletions test/runtime/samples/store-observe-dollar/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Hello {{$name}}!</h1>

0 comments on commit cb8071a

Please sign in to comment.