Merge pull request #822 from chenglou/setstate

better error for bad setState arguments and mergeHelpers
This commit is contained in:
Paul O’Shannessy
2014-01-17 13:05:06 -08:00
2 changed files with 17 additions and 6 deletions

View File

@@ -784,6 +784,18 @@ var ReactCompositeComponentMixin = {
* @protected
*/
setState: function(partialState, callback) {
invariant(
typeof partialState === 'object' || partialState == null,
'setState(...): takes an object of state variables to update.'
);
if (__DEV__){
if (partialState == null) {
console.warn(
'setState(...): You passed an undefined or null state object; ' +
'instead, use forceUpdate().'
);
}
}
// Merge with `_pendingState` if it exists, otherwise with existing state.
this.replaceState(
merge(this._pendingState || this.state, partialState),

View File

@@ -66,9 +66,9 @@ var mergeHelpers = {
checkMergeArrayArgs: function(one, two) {
invariant(
Array.isArray(one) && Array.isArray(two),
'Critical assumptions about the merge functions have been violated. ' +
'This is the fault of the merge functions themselves, not necessarily ' +
'the callers.'
'Tried to merge arrays, instead got %s and %s.',
one,
two
);
},
@@ -87,9 +87,8 @@ var mergeHelpers = {
checkMergeObjectArg: function(arg) {
invariant(
!isTerminal(arg) && !Array.isArray(arg),
'Critical assumptions about the merge functions have been violated. ' +
'This is the fault of the merge functions themselves, not necessarily ' +
'the callers.'
'Tried to merge an object, instead got %s.',
arg
);
},