From 7acb98eca0d93d6a3e343d4c4a8df6afc701d77a Mon Sep 17 00:00:00 2001 From: PaulMaly Date: Tue, 11 Sep 2018 18:11:21 +0300 Subject: [PATCH] Simple type-checking in dev-mode Displays the warning in console if the type of the new value of data property isn't equal to previous. Important in development when interfaces of components are still too fluid. --- src/shared/index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/shared/index.js b/src/shared/index.js index 066942f1a6..9a26948db1 100644 --- a/src/shared/index.js +++ b/src/shared/index.js @@ -138,8 +138,16 @@ export function setDev(newState) { this._debugName + '.set was called without an object of data key-values to update.' ); } - + this._checkReadOnly(newState); + + Object.keys(newState).forEach(prop => { + if (prop in this._state && typeof this._state[prop] !== 'undefined' + && typeof this._state[prop] !== typeof newState[prop]) { + console.warn('Type of data property "' + prop + '" not match with previous one.'); + } + }); + set.call(this, newState); }