-
Notifications
You must be signed in to change notification settings - Fork 47.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add callback validation to fiber-based renderers
Moved ReactFiberClassComponent validateCallback() helper function into a standalone util used by both fiber and stack implementations. Validation now happens in ReactFiberUpdateQueue so that non-DOM renderers will also benefit from it.
- Loading branch information
Brian Vaughn
committed
Jan 3, 2017
1 parent
0402106
commit bc05ef1
Showing
7 changed files
with
59 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Copyright 2013-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @providesModule validateCallback | ||
* @flow | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const invariant = require('invariant'); | ||
|
||
function formatUnexpectedArgument(arg: any) { | ||
let type = typeof arg; | ||
if (type !== 'object') { | ||
return type; | ||
} | ||
let displayName = arg.constructor && arg.constructor.name || type; | ||
let keys = Object.keys(arg); | ||
if (keys.length > 0 && keys.length < 20) { | ||
return `${displayName} (keys: ${keys.join(', ')})`; | ||
} | ||
return displayName; | ||
} | ||
|
||
function validateCallback(callback: ?Function, callerName: string) { | ||
invariant( | ||
!callback || typeof callback === 'function', | ||
'%s(...): Expected the last optional `callback` argument to be a ' + | ||
'function. Instead received: %s.', | ||
callerName, | ||
formatUnexpectedArgument(callback) | ||
); | ||
} | ||
|
||
module.exports = validateCallback; |