Skip to content

Commit

Permalink
emit dev mode error for bad arguments to set - fixes #990
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Dec 10, 2017
1 parent d10f7fb commit 81f4490
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/shared/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,15 @@ export function _set(newState) {
}
}

export function _setDev(newState) {
export function setDev(newState) {
if (typeof newState !== 'object') {
throw new Error(
this._debugName + ' .set was called without an object of data key-values to update.'
this._debugName + '.set was called without an object of data key-values to update.'
);
}

this._checkReadOnly(newState);
_set.call(this, newState);
set.call(this, newState);
}

export function callAll(fns) {
Expand Down Expand Up @@ -220,10 +220,10 @@ export var protoDev = {
fire: fire,
observe: observeDev,
on: onDev,
set: set,
set: setDev,
teardown: destroyDev,
_recompute: noop,
_set: _setDev,
_set: _set,
_mount: _mount,
_unmount: _unmount
};
7 changes: 7 additions & 0 deletions test/runtime/samples/dev-warning-bad-set-argument/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default {
dev: true,

error(assert, error) {
assert.equal(error.message, `<Main$>.set was called without an object of data key-values to update.`);
}
};
11 changes: 11 additions & 0 deletions test/runtime/samples/dev-warning-bad-set-argument/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script>
export default {
data() {
return { key : false };
},

oncreate() {
this.set("key", true);
}
};
</script>

0 comments on commit 81f4490

Please sign in to comment.