Skip to content

Commit 5559da7

Browse files
author
Brian Vaughn
committed
Udpated stack to use new shared validateCallback helper as well
1 parent 52648c3 commit 5559da7

File tree

4 files changed

+15
-46
lines changed

4 files changed

+15
-46
lines changed

src/renderers/dom/fiber/ReactDOMFiber.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,7 @@ function renderSubtreeIntoContainer(parentComponent : ?ReactComponent<any, any,
340340
var ReactDOM = {
341341

342342
render(element : ReactElement<any>, container : DOMContainerElement, callback: ?Function) {
343-
if (callback) {
344-
validateCallback(callback, 'ReactDOM.render');
345-
}
343+
validateCallback(callback, 'ReactDOM.render');
346344
validateContainer(container);
347345
return renderSubtreeIntoContainer(null, element, container, callback);
348346
},

src/renderers/shared/fiber/ReactFiberClassComponent.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,21 @@ module.exports = function(
4343
const updater = {
4444
isMounted,
4545
enqueueSetState(instance, partialState, callback) {
46-
if (callback) {
47-
validateCallback(callback, 'setState');
48-
}
46+
validateCallback(callback, 'setState');
4947
const fiber = ReactInstanceMap.get(instance);
5048
const priorityLevel = getPriorityContext();
5149
addUpdate(fiber, partialState, callback || null, priorityLevel);
5250
scheduleUpdate(fiber, priorityLevel);
5351
},
5452
enqueueReplaceState(instance, state, callback) {
55-
if (callback) {
56-
validateCallback(callback, 'replaceState');
57-
}
53+
validateCallback(callback, 'replaceState');
5854
const fiber = ReactInstanceMap.get(instance);
5955
const priorityLevel = getPriorityContext();
6056
addReplaceUpdate(fiber, state, callback || null, priorityLevel);
6157
scheduleUpdate(fiber, priorityLevel);
6258
},
6359
enqueueForceUpdate(instance, callback) {
64-
if (callback) {
65-
validateCallback(callback, 'forceUpdate');
66-
}
60+
validateCallback(callback, 'forceUpdate');
6761
const fiber = ReactInstanceMap.get(instance);
6862
const priorityLevel = getPriorityContext();
6963
addForceUpdate(fiber, callback || null, priorityLevel);

src/renderers/shared/stack/reconciler/ReactUpdateQueue.js

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,13 @@ var ReactInstanceMap = require('ReactInstanceMap');
1616
var ReactInstrumentation = require('ReactInstrumentation');
1717
var ReactUpdates = require('ReactUpdates');
1818

19-
var invariant = require('invariant');
2019
var warning = require('warning');
20+
var validateCallback = require('validateCallback');
2121

2222
function enqueueUpdate(internalInstance) {
2323
ReactUpdates.enqueueUpdate(internalInstance);
2424
}
2525

26-
function formatUnexpectedArgument(arg) {
27-
var type = typeof arg;
28-
if (type !== 'object') {
29-
return type;
30-
}
31-
var displayName = arg.constructor && arg.constructor.name || type;
32-
var keys = Object.keys(arg);
33-
if (keys.length > 0 && keys.length < 20) {
34-
return `${displayName} (keys: ${keys.join(', ')})`;
35-
}
36-
return displayName;
37-
}
38-
3926
function getInternalInstanceReadyForUpdate(publicInstance, callerName) {
4027
var internalInstance = ReactInstanceMap.get(publicInstance);
4128
if (!internalInstance) {
@@ -253,15 +240,7 @@ var ReactUpdateQueue = {
253240
enqueueUpdate(internalInstance);
254241
},
255242

256-
validateCallback: function(callback, callerName) {
257-
invariant(
258-
!callback || typeof callback === 'function',
259-
'%s(...): Expected the last optional `callback` argument to be a ' +
260-
'function. Instead received: %s.',
261-
callerName,
262-
formatUnexpectedArgument(callback)
263-
);
264-
},
243+
validateCallback: validateCallback,
265244

266245
};
267246

src/renderers/shared/utils/validateCallback.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
const invariant = require('invariant');
1616

17-
function formatUnexpectedArgument(arg) {
17+
function formatUnexpectedArgument(arg: any) {
1818
let type = typeof arg;
1919
if (type !== 'object') {
2020
return type;
@@ -27,16 +27,14 @@ function formatUnexpectedArgument(arg) {
2727
return displayName;
2828
}
2929

30-
function validateCallback(callback: Function, callerName: string) {
31-
if (typeof callback !== 'function') {
32-
invariant(
33-
false,
34-
'%s(...): Expected the last optional `callback` argument to be a ' +
35-
'function. Instead received: %s.',
36-
callerName,
37-
formatUnexpectedArgument(callback)
38-
);
39-
}
30+
function validateCallback(callback: ?Function, callerName: string) {
31+
invariant(
32+
!callback || typeof callback === 'function',
33+
'%s(...): Expected the last optional `callback` argument to be a ' +
34+
'function. Instead received: %s.',
35+
callerName,
36+
formatUnexpectedArgument(callback)
37+
);
4038
}
4139

4240
module.exports = validateCallback;

0 commit comments

Comments
 (0)