Skip to content

Commit

Permalink
Udpated stack to use new shared validateCallback helper as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Jan 3, 2017
1 parent 52648c3 commit 5559da7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 46 deletions.
4 changes: 1 addition & 3 deletions src/renderers/dom/fiber/ReactDOMFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,7 @@ function renderSubtreeIntoContainer(parentComponent : ?ReactComponent<any, any,
var ReactDOM = {

render(element : ReactElement<any>, container : DOMContainerElement, callback: ?Function) {
if (callback) {
validateCallback(callback, 'ReactDOM.render');
}
validateCallback(callback, 'ReactDOM.render');
validateContainer(container);
return renderSubtreeIntoContainer(null, element, container, callback);
},
Expand Down
12 changes: 3 additions & 9 deletions src/renderers/shared/fiber/ReactFiberClassComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,21 @@ module.exports = function(
const updater = {
isMounted,
enqueueSetState(instance, partialState, callback) {
if (callback) {
validateCallback(callback, 'setState');
}
validateCallback(callback, 'setState');
const fiber = ReactInstanceMap.get(instance);
const priorityLevel = getPriorityContext();
addUpdate(fiber, partialState, callback || null, priorityLevel);
scheduleUpdate(fiber, priorityLevel);
},
enqueueReplaceState(instance, state, callback) {
if (callback) {
validateCallback(callback, 'replaceState');
}
validateCallback(callback, 'replaceState');
const fiber = ReactInstanceMap.get(instance);
const priorityLevel = getPriorityContext();
addReplaceUpdate(fiber, state, callback || null, priorityLevel);
scheduleUpdate(fiber, priorityLevel);
},
enqueueForceUpdate(instance, callback) {
if (callback) {
validateCallback(callback, 'forceUpdate');
}
validateCallback(callback, 'forceUpdate');
const fiber = ReactInstanceMap.get(instance);
const priorityLevel = getPriorityContext();
addForceUpdate(fiber, callback || null, priorityLevel);
Expand Down
25 changes: 2 additions & 23 deletions src/renderers/shared/stack/reconciler/ReactUpdateQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,13 @@ var ReactInstanceMap = require('ReactInstanceMap');
var ReactInstrumentation = require('ReactInstrumentation');
var ReactUpdates = require('ReactUpdates');

var invariant = require('invariant');
var warning = require('warning');
var validateCallback = require('validateCallback');

function enqueueUpdate(internalInstance) {
ReactUpdates.enqueueUpdate(internalInstance);
}

function formatUnexpectedArgument(arg) {
var type = typeof arg;
if (type !== 'object') {
return type;
}
var displayName = arg.constructor && arg.constructor.name || type;
var keys = Object.keys(arg);
if (keys.length > 0 && keys.length < 20) {
return `${displayName} (keys: ${keys.join(', ')})`;
}
return displayName;
}

function getInternalInstanceReadyForUpdate(publicInstance, callerName) {
var internalInstance = ReactInstanceMap.get(publicInstance);
if (!internalInstance) {
Expand Down Expand Up @@ -253,15 +240,7 @@ var ReactUpdateQueue = {
enqueueUpdate(internalInstance);
},

validateCallback: function(callback, callerName) {
invariant(
!callback || typeof callback === 'function',
'%s(...): Expected the last optional `callback` argument to be a ' +
'function. Instead received: %s.',
callerName,
formatUnexpectedArgument(callback)
);
},
validateCallback: validateCallback,

};

Expand Down
20 changes: 9 additions & 11 deletions src/renderers/shared/utils/validateCallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

const invariant = require('invariant');

function formatUnexpectedArgument(arg) {
function formatUnexpectedArgument(arg: any) {
let type = typeof arg;
if (type !== 'object') {
return type;
Expand All @@ -27,16 +27,14 @@ function formatUnexpectedArgument(arg) {
return displayName;
}

function validateCallback(callback: Function, callerName: string) {
if (typeof callback !== 'function') {
invariant(
false,
'%s(...): Expected the last optional `callback` argument to be a ' +
'function. Instead received: %s.',
callerName,
formatUnexpectedArgument(callback)
);
}
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;

0 comments on commit 5559da7

Please sign in to comment.