Skip to content

Commit

Permalink
typecheck argument in _set when in dev mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Conduitry committed Mar 6, 2017
1 parent d8dbe4e commit b2cc48b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/generators/dom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@ export default function dom ( parsed, source, options, names ) {
_set: new CodeBuilder()
};

if ( options.dev ) {
builders._set.addBlock ( deindent`
if ( typeof newState !== 'object' ) {
throw new Error( 'Component .set was called without an object of data key-values to update.' );
}
`);
}

builders._set.addLine( 'var oldState = this._state;' );
builders._set.addLine( 'this._state = Object.assign( {}, oldState, newState );' );

Expand Down

0 comments on commit b2cc48b

Please sign in to comment.