-
Notifications
You must be signed in to change notification settings - Fork 47.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8677 from bvaughn/add-callback-validation-to-dom-…
…render Add callback validation to fiber-based renderers
- Loading branch information
Showing
8 changed files
with
63 additions
and
91 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
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; |