Files
react/src/renderers/shared/utils/validateCallback.js
Andrew Clark d3aeca1ff8 Validate callbacks just before they are invoked
This delays the type check until the point when the engine will have to
perform a type check regardless.

Because the error is now thrown during the commit phase rather than
when the callback is originally scheduled, we warn in DEV when
scheduling so it's easier to track down.
2017-02-13 12:12:44 -08:00

27 lines
680 B
JavaScript

/**
* 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 validateCallback(callback: ?Function) {
invariant(
!callback || typeof callback === 'function',
'Invalid argument passed as callback. Expected a function. Instead ' +
'received: %s',
String(callback)
);
}
module.exports = validateCallback;