react-test-renderer
Advanced tools
Comparing version 16.0.0-alpha.3 to 16.0.0-alpha.5
@@ -38,3 +38,3 @@ /** | ||
// Otherwise the build tools will attempt to build a '%s' module. | ||
'React.%s is deprecated. Please use %s.%s from require' + '(\'%s\') ' + 'instead.', fnName, newModule, fnName, newPackage) : void 0; | ||
'React.%s is deprecated. Please use %s.%s from require' + "('%s') " + 'instead.', fnName, newModule, fnName, newPackage) : void 0; | ||
/* eslint-enable no-useless-concat */ | ||
@@ -41,0 +41,0 @@ warned = true; |
@@ -97,3 +97,2 @@ /** | ||
var EventPluginHub = { | ||
/** | ||
@@ -103,3 +102,2 @@ * Methods for injecting dependencies. | ||
injection: { | ||
/** | ||
@@ -115,3 +113,2 @@ * @param {array} InjectedEventPluginOrder | ||
injectEventPluginsByName: EventPluginRegistry.injectEventPluginsByName | ||
}, | ||
@@ -130,3 +127,8 @@ | ||
if (typeof inst.tag === 'number') { | ||
var props = EventPluginUtils.getFiberCurrentPropsFromNode(inst.stateNode); | ||
var stateNode = inst.stateNode; | ||
if (!stateNode) { | ||
// Work in progress (ex: onload events in incremental mode). | ||
return null; | ||
} | ||
var props = EventPluginUtils.getFiberCurrentPropsFromNode(stateNode); | ||
if (!props) { | ||
@@ -141,3 +143,4 @@ // Work in progress. | ||
} else { | ||
if (typeof inst._currentElement === 'string') { | ||
var currentElement = inst._currentElement; | ||
if (typeof currentElement === 'string' || typeof currentElement === 'number') { | ||
// Text node, let it bubble through. | ||
@@ -150,5 +153,5 @@ return null; | ||
} | ||
var _props = inst._currentElement.props; | ||
var _props = currentElement.props; | ||
listener = _props[registrationName]; | ||
if (shouldPreventMouseEvent(registrationName, inst._currentElement.type, _props)) { | ||
if (shouldPreventMouseEvent(registrationName, currentElement.type, _props)) { | ||
return null; | ||
@@ -217,5 +220,4 @@ } | ||
} | ||
}; | ||
module.exports = EventPluginHub; |
@@ -110,3 +110,2 @@ /** | ||
var EventPluginRegistry = { | ||
/** | ||
@@ -183,73 +182,5 @@ * Ordered list of injected plugins. | ||
} | ||
}, | ||
/** | ||
* Looks up the plugin for the supplied event. | ||
* | ||
* @param {object} event A synthetic event. | ||
* @return {?object} The plugin that created the supplied event. | ||
* @internal | ||
*/ | ||
getPluginModuleForEvent: function (event) { | ||
var dispatchConfig = event.dispatchConfig; | ||
if (dispatchConfig.registrationName) { | ||
return EventPluginRegistry.registrationNameModules[dispatchConfig.registrationName] || null; | ||
} | ||
if (dispatchConfig.phasedRegistrationNames !== undefined) { | ||
// pulling phasedRegistrationNames out of dispatchConfig helps Flow see | ||
// that it is not undefined. | ||
var phasedRegistrationNames = dispatchConfig.phasedRegistrationNames; | ||
for (var phase in phasedRegistrationNames) { | ||
if (!phasedRegistrationNames.hasOwnProperty(phase)) { | ||
continue; | ||
} | ||
var pluginModule = EventPluginRegistry.registrationNameModules[phasedRegistrationNames[phase]]; | ||
if (pluginModule) { | ||
return pluginModule; | ||
} | ||
} | ||
} | ||
return null; | ||
}, | ||
/** | ||
* Exposed for unit testing. | ||
* @private | ||
*/ | ||
_resetEventPlugins: function () { | ||
eventPluginOrder = null; | ||
for (var pluginName in namesToPlugins) { | ||
if (namesToPlugins.hasOwnProperty(pluginName)) { | ||
delete namesToPlugins[pluginName]; | ||
} | ||
} | ||
EventPluginRegistry.plugins.length = 0; | ||
var eventNameDispatchConfigs = EventPluginRegistry.eventNameDispatchConfigs; | ||
for (var eventName in eventNameDispatchConfigs) { | ||
if (eventNameDispatchConfigs.hasOwnProperty(eventName)) { | ||
delete eventNameDispatchConfigs[eventName]; | ||
} | ||
} | ||
var registrationNameModules = EventPluginRegistry.registrationNameModules; | ||
for (var registrationName in registrationNameModules) { | ||
if (registrationNameModules.hasOwnProperty(registrationName)) { | ||
delete registrationNameModules[registrationName]; | ||
} | ||
} | ||
if (process.env.NODE_ENV !== 'production') { | ||
var possibleRegistrationNames = EventPluginRegistry.possibleRegistrationNames; | ||
for (var lowerCasedName in possibleRegistrationNames) { | ||
if (possibleRegistrationNames.hasOwnProperty(lowerCasedName)) { | ||
delete possibleRegistrationNames[lowerCasedName]; | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
module.exports = EventPluginRegistry; |
@@ -75,7 +75,3 @@ /** | ||
event.currentTarget = EventPluginUtils.getNodeFromInstance(inst); | ||
if (simulated) { | ||
ReactErrorUtils.invokeGuardedCallbackWithCatch(type, listener, event); | ||
} else { | ||
ReactErrorUtils.invokeGuardedCallback(type, listener, event); | ||
} | ||
ReactErrorUtils.invokeGuardedCallbackAndCatchFirstError(type, listener, undefined, event); | ||
event.currentTarget = null; | ||
@@ -82,0 +78,0 @@ } |
'use strict'; | ||
var _prodInvariant = require('./reactProdInvariant'); | ||
/** | ||
@@ -6,0 +4,0 @@ * Copyright 2013-present, Facebook, Inc. |
@@ -70,3 +70,3 @@ /** | ||
if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) { | ||
info += ' You likely forgot to export your component from the file ' + 'it\'s defined in.'; | ||
info += ' You likely forgot to export your component from the file ' + "it's defined in."; | ||
} | ||
@@ -73,0 +73,0 @@ } |
@@ -19,17 +19,17 @@ /** | ||
var supportedInputTypes = { | ||
'color': true, | ||
'date': true, | ||
'datetime': true, | ||
color: true, | ||
date: true, | ||
datetime: true, | ||
'datetime-local': true, | ||
'email': true, | ||
'month': true, | ||
'number': true, | ||
'password': true, | ||
'range': true, | ||
'search': true, | ||
'tel': true, | ||
'text': true, | ||
'time': true, | ||
'url': true, | ||
'week': true | ||
email: true, | ||
month: true, | ||
number: true, | ||
password: true, | ||
range: true, | ||
search: true, | ||
tel: true, | ||
text: true, | ||
time: true, | ||
url: true, | ||
week: true | ||
}; | ||
@@ -36,0 +36,0 @@ |
@@ -39,5 +39,3 @@ /** | ||
var _require4 = require('./ReactFiberTreeReflection'), | ||
getComponentName = _require4.getComponentName; | ||
var getComponentName = require('./getComponentName'); | ||
var warning = require('fbjs/lib/warning'); | ||
@@ -74,30 +72,38 @@ var didWarnAboutMaps = false; | ||
if (element._owner) { | ||
var owner = element._owner; | ||
var inst = void 0; | ||
if (owner) { | ||
if (typeof owner.tag === 'number') { | ||
var ownerFiber = owner; | ||
!(ownerFiber.tag === ClassComponent) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Stateless function components cannot have refs.') : _prodInvariant('110') : void 0; | ||
inst = ownerFiber.stateNode; | ||
} else { | ||
// Stack | ||
inst = owner.getPublicInstance(); | ||
var _ret = function () { | ||
var owner = element._owner; | ||
var inst = void 0; | ||
if (owner) { | ||
if (typeof owner.tag === 'number') { | ||
var ownerFiber = owner; | ||
!(ownerFiber.tag === ClassComponent) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Stateless function components cannot have refs.') : _prodInvariant('110') : void 0; | ||
inst = ownerFiber.stateNode; | ||
} else { | ||
// Stack | ||
inst = owner.getPublicInstance(); | ||
} | ||
} | ||
} | ||
invariant(inst, 'Missing owner for string ref %s. This error is likely caused by a ' + 'bug in React. Please file an issue.', mixedRef); | ||
var stringRef = String(mixedRef); | ||
// Check if previous string ref matches new string ref | ||
if (current !== null && current.ref !== null && current.ref._stringRef === stringRef) { | ||
return current.ref; | ||
} | ||
var ref = function (value) { | ||
var refs = inst.refs === emptyObject ? inst.refs = {} : inst.refs; | ||
if (value === null) { | ||
delete refs[stringRef]; | ||
} else { | ||
refs[stringRef] = value; | ||
invariant(inst, 'Missing owner for string ref %s. This error is likely caused by a ' + 'bug in React. Please file an issue.', mixedRef); | ||
var stringRef = '' + mixedRef; | ||
// Check if previous string ref matches new string ref | ||
if (current !== null && current.ref !== null && current.ref._stringRef === stringRef) { | ||
return { | ||
v: current.ref | ||
}; | ||
} | ||
}; | ||
ref._stringRef = stringRef; | ||
return ref; | ||
var ref = function (value) { | ||
var refs = inst.refs === emptyObject ? inst.refs = {} : inst.refs; | ||
if (value === null) { | ||
delete refs[stringRef]; | ||
} else { | ||
refs[stringRef] = value; | ||
} | ||
}; | ||
ref._stringRef = stringRef; | ||
return { | ||
v: ref | ||
}; | ||
}(); | ||
if (typeof _ret === "object") return _ret.v; | ||
} | ||
@@ -110,6 +116,5 @@ } | ||
if (returnFiber.type !== 'textarea') { | ||
var childrenString = String(newChild); | ||
var addendum = ''; | ||
if (process.env.NODE_ENV !== 'production') { | ||
addendum = ' If you meant to render a collection of children, use an array ' + 'instead or wrap the object using createFragment(object) from the ' + 'React add-ons.'; | ||
addendum = ' If you meant to render a collection of children, use an array ' + 'instead.'; | ||
var owner = ReactCurrentOwner.owner || returnFiber._debugOwner; | ||
@@ -123,3 +128,3 @@ if (owner && typeof owner.tag === 'number') { | ||
} | ||
!false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Objects are not valid as a React child (found: %s).%s', childrenString === '[object Object]' ? 'object with keys {' + Object.keys(newChild).join(', ') + '}' : childrenString, addendum) : _prodInvariant('31', childrenString === '[object Object]' ? 'object with keys {' + Object.keys(newChild).join(', ') + '}' : childrenString, addendum) : void 0; | ||
!false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Objects are not valid as a React child (found: %s).%s', Object.prototype.toString.call(newChild) === '[object Object]' ? 'object with keys {' + Object.keys(newChild).join(', ') + '}' : newChild, addendum) : _prodInvariant('31', Object.prototype.toString.call(newChild) === '[object Object]' ? 'object with keys {' + Object.keys(newChild).join(', ') + '}' : newChild, addendum) : void 0; | ||
} | ||
@@ -133,3 +138,2 @@ } | ||
function ChildReconciler(shouldClone, shouldTrackSideEffects) { | ||
function deleteChild(returnFiber, childToDelete) { | ||
@@ -473,3 +477,2 @@ if (!shouldTrackSideEffects) { | ||
function updateFromMap(existingChildren, returnFiber, newIdx, newChild, priority) { | ||
if (typeof newChild === 'string' || typeof newChild === 'number') { | ||
@@ -554,3 +557,2 @@ // Text nodes doesn't have keys, so we neither have to check the old nor | ||
function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, priority) { | ||
// This algorithm can't optimize by searching from boths ends since we | ||
@@ -695,3 +697,2 @@ // don't have backpointers on fibers. I'm trying to see how far we can get | ||
function reconcileChildrenIterator(returnFiber, currentFirstChild, newChildrenIterable, priority) { | ||
// This is the same implementation as reconcileChildrenArray(), | ||
@@ -1130,13 +1131,13 @@ // but using the iterator instead. | ||
newChild.sibling = null; | ||
} else { | ||
// If there is no alternate, then we don't need to clone the children. | ||
// If the children of the alternate fiber is a different set, then we don't | ||
// need to clone. We need to reset the return fiber though since we'll | ||
// traverse down into them. | ||
var child = workInProgress.child; | ||
while (child !== null) { | ||
child['return'] = workInProgress; | ||
child = child.sibling; | ||
} | ||
} | ||
// If there is no alternate, then we don't need to clone the children. | ||
// If the children of the alternate fiber is a different set, then we don't | ||
// need to clone. We need to reset the return fiber though since we'll | ||
// traverse down into them. | ||
var child = workInProgress.child; | ||
while (child !== null) { | ||
child['return'] = workInProgress; | ||
child = child.sibling; | ||
} | ||
}; |
@@ -63,4 +63,4 @@ /** | ||
*/ | ||
instantiateChildren: function (nestedChildNodes, transaction, context, selfDebugID // 0 in production and for roots | ||
) { | ||
instantiateChildren: function (nestedChildNodes, transaction, context, selfDebugID) // 0 in production and for roots | ||
{ | ||
if (nestedChildNodes == null) { | ||
@@ -91,4 +91,4 @@ return null; | ||
*/ | ||
updateChildren: function (prevChildren, nextChildren, mountImages, removedNodes, transaction, hostParent, hostContainerInfo, context, selfDebugID // 0 in production and for roots | ||
) { | ||
updateChildren: function (prevChildren, nextChildren, mountImages, removedNodes, transaction, hostParent, hostContainerInfo, context, selfDebugID) // 0 in production and for roots | ||
{ | ||
// We currently don't have a way to track moves here but if we use iterators | ||
@@ -117,4 +117,4 @@ // instead of for..in we can zip the iterators and check if an item has | ||
removedNodes[name] = ReactReconciler.getHostNode(prevChild); | ||
ReactReconciler.unmountComponent(prevChild, false, /* safely */ | ||
false /* skipLifecycle */ | ||
ReactReconciler.unmountComponent(prevChild, false /* safely */ | ||
, false /* skipLifecycle */ | ||
); | ||
@@ -131,4 +131,4 @@ } | ||
removedNodes[name] = ReactReconciler.getHostNode(prevChild); | ||
ReactReconciler.unmountComponent(prevChild, false, /* safely */ | ||
false /* skipLifecycle */ | ||
ReactReconciler.unmountComponent(prevChild, false /* safely */ | ||
, false /* skipLifecycle */ | ||
); | ||
@@ -143,4 +143,4 @@ } | ||
removedNodes[name] = ReactReconciler.getHostNode(prevChild); | ||
ReactReconciler.unmountComponent(prevChild, false, /* safely */ | ||
false /* skipLifecycle */ | ||
ReactReconciler.unmountComponent(prevChild, false /* safely */ | ||
, false /* skipLifecycle */ | ||
); | ||
@@ -166,5 +166,4 @@ } | ||
} | ||
}; | ||
module.exports = ReactChildReconciler; |
@@ -21,3 +21,2 @@ /** | ||
var ReactComponentEnvironment = { | ||
/** | ||
@@ -43,5 +42,4 @@ * Optionally injectable hook for swapping out mount images in the middle of | ||
} | ||
}; | ||
module.exports = ReactComponentEnvironment; |
@@ -110,3 +110,2 @@ /** | ||
var ReactCompositeComponent = { | ||
/** | ||
@@ -209,3 +208,3 @@ * Base constructor for all composite component. | ||
process.env.NODE_ENV !== 'production' ? warning(inst.props === undefined || !propsMutated, '%s(...): When calling super() in `%s`, make sure to pass ' + 'up the same props that your component\'s constructor was passed.', componentName, componentName) : void 0; | ||
process.env.NODE_ENV !== 'production' ? warning(inst.props === undefined || !propsMutated, '%s(...): When calling super() in `%s`, make sure to pass ' + "up the same props that your component's constructor was passed.", componentName, componentName) : void 0; | ||
} | ||
@@ -344,4 +343,4 @@ | ||
checkpoint = transaction.checkpoint(); | ||
this._renderedComponent.unmountComponent(true, /* safely */ | ||
// Don't call componentWillUnmount() because they never fully mounted: | ||
this._renderedComponent.unmountComponent(true /* safely */ | ||
, // Don't call componentWillUnmount() because they never fully mounted: | ||
true /* skipLifecyle */ | ||
@@ -410,3 +409,3 @@ ); | ||
var name = this.getName() + '.componentWillUnmount()'; | ||
ReactErrorUtils.invokeGuardedCallback(name, inst.componentWillUnmount.bind(inst)); | ||
ReactErrorUtils.invokeGuardedCallbackAndCatchFirstError(name, inst.componentWillUnmount, inst); | ||
} | ||
@@ -645,3 +644,3 @@ } else { | ||
if (process.env.NODE_ENV !== 'production') { | ||
process.env.NODE_ENV !== 'production' ? warning(false, '%s.componentWillReceiveProps(): Assigning directly to ' + 'this.state is deprecated (except inside a component\'s ' + 'constructor). Use setState instead.', this.getName() || 'ReactCompositeComponent') : void 0; | ||
process.env.NODE_ENV !== 'production' ? warning(false, '%s.componentWillReceiveProps(): Assigning directly to ' + "this.state is deprecated (except inside a component's " + 'constructor). Use setState instead.', this.getName() || 'ReactCompositeComponent') : void 0; | ||
} | ||
@@ -752,3 +751,3 @@ } | ||
var hasComponentDidUpdate = Boolean(inst.componentDidUpdate); | ||
var hasComponentDidUpdate = !!inst.componentDidUpdate; | ||
var prevProps; | ||
@@ -1003,5 +1002,4 @@ var prevState; | ||
_instantiateReactComponent: null | ||
}; | ||
module.exports = ReactCompositeComponent; |
@@ -13,4 +13,2 @@ /** | ||
var _prodInvariant = require('./reactProdInvariant'); | ||
var EventPluginUtils = require('./EventPluginUtils'); | ||
@@ -17,0 +15,0 @@ |
@@ -17,3 +17,3 @@ /** | ||
var _require = require('react/lib/ReactComponentTreeHook'), | ||
var _require = require('./ReactFiberComponentTreeHook'), | ||
getStackAddendumByWorkInProgressFiber = _require.getStackAddendumByWorkInProgressFiber; | ||
@@ -50,2 +50,4 @@ } | ||
current: null, | ||
phase: null, | ||
getCurrentFiberOwnerName: getCurrentFiberOwnerName, | ||
@@ -52,0 +54,0 @@ getCurrentFiberStackAddendum: getCurrentFiberStackAddendum |
@@ -26,335 +26,357 @@ /** | ||
if (process.env.NODE_ENV !== 'production') { | ||
var hooks = []; | ||
var didHookThrowForEvent = {}; | ||
var hooks; | ||
var didHookThrowForEvent; | ||
var isProfiling; | ||
var flushHistory; | ||
var lifeCycleTimerStack; | ||
var currentFlushNesting; | ||
var currentFlushMeasurements; | ||
var currentFlushStartTime; | ||
var currentTimerDebugID; | ||
var currentTimerStartTime; | ||
var currentTimerNestedFlushDuration; | ||
var currentTimerType; | ||
var lifeCycleTimerHasWarned; | ||
var lastMarkTimeStamp; | ||
var canUsePerformanceMeasure; | ||
var url; | ||
var callHook = function (event, fn, context, arg1, arg2, arg3, arg4, arg5) { | ||
try { | ||
fn.call(context, arg1, arg2, arg3, arg4, arg5); | ||
} catch (e) { | ||
process.env.NODE_ENV !== 'production' ? warning(didHookThrowForEvent[event], 'Exception thrown by hook while handling %s: %s', event, e + '\n' + e.stack) : void 0; | ||
didHookThrowForEvent[event] = true; | ||
} | ||
}; | ||
(function () { | ||
hooks = []; | ||
didHookThrowForEvent = {}; | ||
var emitEvent = function (event, arg1, arg2, arg3, arg4, arg5) { | ||
for (var i = 0; i < hooks.length; i++) { | ||
var hook = hooks[i]; | ||
var fn = hook[event]; | ||
if (fn) { | ||
callHook(event, fn, hook, arg1, arg2, arg3, arg4, arg5); | ||
var callHook = function (event, fn, context, arg1, arg2, arg3, arg4, arg5) { | ||
try { | ||
fn.call(context, arg1, arg2, arg3, arg4, arg5); | ||
} catch (e) { | ||
process.env.NODE_ENV !== 'production' ? warning(didHookThrowForEvent[event], 'Exception thrown by hook while handling %s: %s', event, e + '\n' + e.stack) : void 0; | ||
didHookThrowForEvent[event] = true; | ||
} | ||
} | ||
}; | ||
}; | ||
var isProfiling = false; | ||
var flushHistory = []; | ||
var lifeCycleTimerStack = []; | ||
var currentFlushNesting = 0; | ||
var currentFlushMeasurements = []; | ||
var currentFlushStartTime = 0; | ||
var currentTimerDebugID = null; | ||
var currentTimerStartTime = 0; | ||
var currentTimerNestedFlushDuration = 0; | ||
var currentTimerType = null; | ||
var emitEvent = function (event, arg1, arg2, arg3, arg4, arg5) { | ||
for (var i = 0; i < hooks.length; i++) { | ||
var hook = hooks[i]; | ||
var fn = hook[event]; | ||
if (fn) { | ||
callHook(event, fn, hook, arg1, arg2, arg3, arg4, arg5); | ||
} | ||
} | ||
}; | ||
var lifeCycleTimerHasWarned = false; | ||
isProfiling = false; | ||
flushHistory = []; | ||
lifeCycleTimerStack = []; | ||
currentFlushNesting = 0; | ||
currentFlushMeasurements = []; | ||
currentFlushStartTime = 0; | ||
currentTimerDebugID = null; | ||
currentTimerStartTime = 0; | ||
currentTimerNestedFlushDuration = 0; | ||
currentTimerType = null; | ||
lifeCycleTimerHasWarned = false; | ||
var clearHistory = function () { | ||
ReactComponentTreeHook.purgeUnmountedComponents(); | ||
ReactHostOperationHistoryHook.clearHistory(); | ||
}; | ||
var getTreeSnapshot = function (registeredIDs) { | ||
return registeredIDs.reduce(function (tree, id) { | ||
var ownerID = ReactComponentTreeHook.getOwnerID(id); | ||
var parentID = ReactComponentTreeHook.getParentID(id); | ||
tree[id] = { | ||
displayName: ReactComponentTreeHook.getDisplayName(id), | ||
text: ReactComponentTreeHook.getText(id), | ||
updateCount: ReactComponentTreeHook.getUpdateCount(id), | ||
childIDs: ReactComponentTreeHook.getChildIDs(id), | ||
// Text nodes don't have owners but this is close enough. | ||
ownerID: ownerID || parentID && ReactComponentTreeHook.getOwnerID(parentID) || 0, | ||
parentID: parentID | ||
}; | ||
return tree; | ||
}, {}); | ||
}; | ||
var clearHistory = function () { | ||
ReactComponentTreeHook.purgeUnmountedComponents(); | ||
ReactHostOperationHistoryHook.clearHistory(); | ||
}; | ||
var resetMeasurements = function () { | ||
var previousStartTime = currentFlushStartTime; | ||
var previousMeasurements = currentFlushMeasurements; | ||
var previousOperations = ReactHostOperationHistoryHook.getHistory(); | ||
var getTreeSnapshot = function (registeredIDs) { | ||
return registeredIDs.reduce(function (tree, id) { | ||
var ownerID = ReactComponentTreeHook.getOwnerID(id); | ||
var parentID = ReactComponentTreeHook.getParentID(id); | ||
tree[id] = { | ||
displayName: ReactComponentTreeHook.getDisplayName(id), | ||
text: ReactComponentTreeHook.getText(id), | ||
updateCount: ReactComponentTreeHook.getUpdateCount(id), | ||
childIDs: ReactComponentTreeHook.getChildIDs(id), | ||
// Text nodes don't have owners but this is close enough. | ||
ownerID: ownerID || parentID && ReactComponentTreeHook.getOwnerID(parentID) || 0, | ||
parentID: parentID | ||
}; | ||
return tree; | ||
}, {}); | ||
}; | ||
if (currentFlushNesting === 0) { | ||
currentFlushStartTime = 0; | ||
var resetMeasurements = function () { | ||
var previousStartTime = currentFlushStartTime; | ||
var previousMeasurements = currentFlushMeasurements; | ||
var previousOperations = ReactHostOperationHistoryHook.getHistory(); | ||
if (currentFlushNesting === 0) { | ||
currentFlushStartTime = 0; | ||
currentFlushMeasurements = []; | ||
clearHistory(); | ||
return; | ||
} | ||
if (previousMeasurements.length || previousOperations.length) { | ||
var registeredIDs = ReactComponentTreeHook.getRegisteredIDs(); | ||
flushHistory.push({ | ||
duration: performanceNow() - previousStartTime, | ||
measurements: previousMeasurements || [], | ||
operations: previousOperations || [], | ||
treeSnapshot: getTreeSnapshot(registeredIDs) | ||
}); | ||
} | ||
clearHistory(); | ||
currentFlushStartTime = performanceNow(); | ||
currentFlushMeasurements = []; | ||
clearHistory(); | ||
return; | ||
} | ||
}; | ||
if (previousMeasurements.length || previousOperations.length) { | ||
var registeredIDs = ReactComponentTreeHook.getRegisteredIDs(); | ||
flushHistory.push({ | ||
duration: performanceNow() - previousStartTime, | ||
measurements: previousMeasurements || [], | ||
operations: previousOperations || [], | ||
treeSnapshot: getTreeSnapshot(registeredIDs) | ||
}); | ||
} | ||
var checkDebugID = function (debugID) { | ||
var allowRoot = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
clearHistory(); | ||
currentFlushStartTime = performanceNow(); | ||
currentFlushMeasurements = []; | ||
}; | ||
if (allowRoot && debugID === 0) { | ||
return; | ||
} | ||
if (!debugID) { | ||
process.env.NODE_ENV !== 'production' ? warning(false, 'ReactDebugTool: debugID may not be empty.') : void 0; | ||
} | ||
}; | ||
var checkDebugID = function (debugID) { | ||
var allowRoot = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
var beginLifeCycleTimer = function (debugID, timerType) { | ||
if (currentFlushNesting === 0) { | ||
return; | ||
} | ||
if (currentTimerType && !lifeCycleTimerHasWarned) { | ||
process.env.NODE_ENV !== 'production' ? warning(false, 'There is an internal error in the React performance measurement code.' + '\n\nDid not expect %s timer to start while %s timer is still in ' + 'progress for %s instance.', timerType, currentTimerType || 'no', debugID === currentTimerDebugID ? 'the same' : 'another') : void 0; | ||
lifeCycleTimerHasWarned = true; | ||
} | ||
currentTimerStartTime = performanceNow(); | ||
currentTimerNestedFlushDuration = 0; | ||
currentTimerDebugID = debugID; | ||
currentTimerType = timerType; | ||
}; | ||
if (allowRoot && debugID === 0) { | ||
return; | ||
} | ||
if (!debugID) { | ||
process.env.NODE_ENV !== 'production' ? warning(false, 'ReactDebugTool: debugID may not be empty.') : void 0; | ||
} | ||
}; | ||
var endLifeCycleTimer = function (debugID, timerType) { | ||
if (currentFlushNesting === 0) { | ||
return; | ||
} | ||
if (currentTimerType !== timerType && !lifeCycleTimerHasWarned) { | ||
process.env.NODE_ENV !== 'production' ? warning(false, 'There is an internal error in the React performance measurement code. ' + 'We did not expect %s timer to stop while %s timer is still in ' + 'progress for %s instance. Please report this as a bug in React.', timerType, currentTimerType || 'no', debugID === currentTimerDebugID ? 'the same' : 'another') : void 0; | ||
lifeCycleTimerHasWarned = true; | ||
} | ||
if (isProfiling) { | ||
currentFlushMeasurements.push({ | ||
timerType: timerType, | ||
instanceID: debugID, | ||
duration: performanceNow() - currentTimerStartTime - currentTimerNestedFlushDuration | ||
}); | ||
} | ||
currentTimerStartTime = 0; | ||
currentTimerNestedFlushDuration = 0; | ||
currentTimerDebugID = null; | ||
currentTimerType = null; | ||
}; | ||
var beginLifeCycleTimer = function (debugID, timerType) { | ||
if (currentFlushNesting === 0) { | ||
return; | ||
} | ||
if (currentTimerType && !lifeCycleTimerHasWarned) { | ||
process.env.NODE_ENV !== 'production' ? warning(false, 'There is an internal error in the React performance measurement code.' + '\n\nDid not expect %s timer to start while %s timer is still in ' + 'progress for %s instance.', timerType, currentTimerType || 'no', debugID === currentTimerDebugID ? 'the same' : 'another') : void 0; | ||
lifeCycleTimerHasWarned = true; | ||
} | ||
currentTimerStartTime = performanceNow(); | ||
currentTimerNestedFlushDuration = 0; | ||
currentTimerDebugID = debugID; | ||
currentTimerType = timerType; | ||
}; | ||
var pauseCurrentLifeCycleTimer = function () { | ||
var currentTimer = { | ||
startTime: currentTimerStartTime, | ||
nestedFlushStartTime: performanceNow(), | ||
debugID: currentTimerDebugID, | ||
timerType: currentTimerType | ||
}; | ||
lifeCycleTimerStack.push(currentTimer); | ||
currentTimerStartTime = 0; | ||
currentTimerNestedFlushDuration = 0; | ||
currentTimerDebugID = null; | ||
currentTimerType = null; | ||
}; | ||
var endLifeCycleTimer = function (debugID, timerType) { | ||
if (currentFlushNesting === 0) { | ||
return; | ||
} | ||
if (currentTimerType !== timerType && !lifeCycleTimerHasWarned) { | ||
process.env.NODE_ENV !== 'production' ? warning(false, 'There is an internal error in the React performance measurement code. ' + 'We did not expect %s timer to stop while %s timer is still in ' + 'progress for %s instance. Please report this as a bug in React.', timerType, currentTimerType || 'no', debugID === currentTimerDebugID ? 'the same' : 'another') : void 0; | ||
lifeCycleTimerHasWarned = true; | ||
} | ||
if (isProfiling) { | ||
currentFlushMeasurements.push({ | ||
timerType: timerType, | ||
instanceID: debugID, | ||
duration: performanceNow() - currentTimerStartTime - currentTimerNestedFlushDuration | ||
}); | ||
} | ||
currentTimerStartTime = 0; | ||
currentTimerNestedFlushDuration = 0; | ||
currentTimerDebugID = null; | ||
currentTimerType = null; | ||
}; | ||
var resumeCurrentLifeCycleTimer = function () { | ||
var _lifeCycleTimerStack$ = lifeCycleTimerStack.pop(), | ||
startTime = _lifeCycleTimerStack$.startTime, | ||
nestedFlushStartTime = _lifeCycleTimerStack$.nestedFlushStartTime, | ||
debugID = _lifeCycleTimerStack$.debugID, | ||
timerType = _lifeCycleTimerStack$.timerType; | ||
var pauseCurrentLifeCycleTimer = function () { | ||
var currentTimer = { | ||
startTime: currentTimerStartTime, | ||
nestedFlushStartTime: performanceNow(), | ||
debugID: currentTimerDebugID, | ||
timerType: currentTimerType | ||
var nestedFlushDuration = performanceNow() - nestedFlushStartTime; | ||
currentTimerStartTime = startTime; | ||
currentTimerNestedFlushDuration += nestedFlushDuration; | ||
currentTimerDebugID = debugID; | ||
currentTimerType = timerType; | ||
}; | ||
lifeCycleTimerStack.push(currentTimer); | ||
currentTimerStartTime = 0; | ||
currentTimerNestedFlushDuration = 0; | ||
currentTimerDebugID = null; | ||
currentTimerType = null; | ||
}; | ||
var resumeCurrentLifeCycleTimer = function () { | ||
var _lifeCycleTimerStack$ = lifeCycleTimerStack.pop(), | ||
startTime = _lifeCycleTimerStack$.startTime, | ||
nestedFlushStartTime = _lifeCycleTimerStack$.nestedFlushStartTime, | ||
debugID = _lifeCycleTimerStack$.debugID, | ||
timerType = _lifeCycleTimerStack$.timerType; | ||
lastMarkTimeStamp = 0; | ||
canUsePerformanceMeasure = typeof performance !== 'undefined' && typeof performance.mark === 'function' && typeof performance.clearMarks === 'function' && typeof performance.measure === 'function' && typeof performance.clearMeasures === 'function'; | ||
var nestedFlushDuration = performanceNow() - nestedFlushStartTime; | ||
currentTimerStartTime = startTime; | ||
currentTimerNestedFlushDuration += nestedFlushDuration; | ||
currentTimerDebugID = debugID; | ||
currentTimerType = timerType; | ||
}; | ||
var lastMarkTimeStamp = 0; | ||
var canUsePerformanceMeasure = typeof performance !== 'undefined' && typeof performance.mark === 'function' && typeof performance.clearMarks === 'function' && typeof performance.measure === 'function' && typeof performance.clearMeasures === 'function'; | ||
var shouldMark = function (debugID) { | ||
if (!isProfiling || !canUsePerformanceMeasure) { | ||
return false; | ||
} | ||
var element = ReactComponentTreeHook.getElement(debugID); | ||
if (element == null || typeof element !== 'object') { | ||
return false; | ||
} | ||
var isHostElement = typeof element.type === 'string'; | ||
if (isHostElement) { | ||
return false; | ||
} | ||
return true; | ||
}; | ||
var shouldMark = function (debugID) { | ||
if (!isProfiling || !canUsePerformanceMeasure) { | ||
return false; | ||
} | ||
var element = ReactComponentTreeHook.getElement(debugID); | ||
if (element == null || typeof element !== 'object') { | ||
return false; | ||
} | ||
var isHostElement = typeof element.type === 'string'; | ||
if (isHostElement) { | ||
return false; | ||
} | ||
return true; | ||
}; | ||
var markBegin = function (debugID, markType) { | ||
if (!shouldMark(debugID)) { | ||
return; | ||
} | ||
var markBegin = function (debugID, markType) { | ||
if (!shouldMark(debugID)) { | ||
return; | ||
} | ||
var markName = debugID + '::' + markType; | ||
lastMarkTimeStamp = performanceNow(); | ||
performance.mark(markName); | ||
}; | ||
var markName = debugID + '::' + markType; | ||
lastMarkTimeStamp = performanceNow(); | ||
performance.mark(markName); | ||
}; | ||
var markEnd = function (debugID, markType) { | ||
if (!shouldMark(debugID)) { | ||
return; | ||
} | ||
var markEnd = function (debugID, markType) { | ||
if (!shouldMark(debugID)) { | ||
return; | ||
} | ||
var markName = debugID + '::' + markType; | ||
var displayName = ReactComponentTreeHook.getDisplayName(debugID) || 'Unknown'; | ||
var markName = debugID + '::' + markType; | ||
var displayName = ReactComponentTreeHook.getDisplayName(debugID) || 'Unknown'; | ||
// Chrome has an issue of dropping markers recorded too fast: | ||
// https://bugs.chromium.org/p/chromium/issues/detail?id=640652 | ||
// To work around this, we will not report very small measurements. | ||
// I determined the magic number by tweaking it back and forth. | ||
// 0.05ms was enough to prevent the issue, but I set it to 0.1ms to be safe. | ||
// When the bug is fixed, we can `measure()` unconditionally if we want to. | ||
var timeStamp = performanceNow(); | ||
if (timeStamp - lastMarkTimeStamp > 0.1) { | ||
var measurementName = displayName + ' [' + markType + ']'; | ||
performance.measure(measurementName, markName); | ||
} | ||
// Chrome has an issue of dropping markers recorded too fast: | ||
// https://bugs.chromium.org/p/chromium/issues/detail?id=640652 | ||
// To work around this, we will not report very small measurements. | ||
// I determined the magic number by tweaking it back and forth. | ||
// 0.05ms was enough to prevent the issue, but I set it to 0.1ms to be safe. | ||
// When the bug is fixed, we can `measure()` unconditionally if we want to. | ||
var timeStamp = performanceNow(); | ||
if (timeStamp - lastMarkTimeStamp > 0.1) { | ||
var measurementName = displayName + ' [' + markType + ']'; | ||
performance.measure(measurementName, markName); | ||
} | ||
performance.clearMarks(markName); | ||
performance.clearMeasures(measurementName); | ||
}; | ||
performance.clearMarks(markName); | ||
performance.clearMeasures(measurementName); | ||
}; | ||
ReactDebugTool = { | ||
addHook: function (hook) { | ||
hooks.push(hook); | ||
}, | ||
removeHook: function (hook) { | ||
for (var i = 0; i < hooks.length; i++) { | ||
if (hooks[i] === hook) { | ||
hooks.splice(i, 1); | ||
i--; | ||
} | ||
} | ||
}, | ||
isProfiling: function () { | ||
return isProfiling; | ||
}, | ||
beginProfiling: function () { | ||
if (isProfiling) { | ||
return; | ||
} | ||
ReactDebugTool = { | ||
addHook: function (hook) { | ||
hooks.push(hook); | ||
}, | ||
removeHook: function (hook) { | ||
for (var i = 0; i < hooks.length; i++) { | ||
if (hooks[i] === hook) { | ||
hooks.splice(i, 1); | ||
i--; | ||
isProfiling = true; | ||
flushHistory.length = 0; | ||
resetMeasurements(); | ||
ReactDebugTool.addHook(ReactHostOperationHistoryHook); | ||
}, | ||
endProfiling: function () { | ||
if (!isProfiling) { | ||
return; | ||
} | ||
} | ||
}, | ||
isProfiling: function () { | ||
return isProfiling; | ||
}, | ||
beginProfiling: function () { | ||
if (isProfiling) { | ||
return; | ||
} | ||
isProfiling = true; | ||
flushHistory.length = 0; | ||
resetMeasurements(); | ||
ReactDebugTool.addHook(ReactHostOperationHistoryHook); | ||
}, | ||
endProfiling: function () { | ||
if (!isProfiling) { | ||
return; | ||
isProfiling = false; | ||
resetMeasurements(); | ||
ReactDebugTool.removeHook(ReactHostOperationHistoryHook); | ||
}, | ||
getFlushHistory: function () { | ||
return flushHistory; | ||
}, | ||
onBeginFlush: function () { | ||
currentFlushNesting++; | ||
resetMeasurements(); | ||
pauseCurrentLifeCycleTimer(); | ||
emitEvent('onBeginFlush'); | ||
}, | ||
onEndFlush: function () { | ||
resetMeasurements(); | ||
currentFlushNesting--; | ||
resumeCurrentLifeCycleTimer(); | ||
emitEvent('onEndFlush'); | ||
}, | ||
onBeginLifeCycleTimer: function (debugID, timerType) { | ||
checkDebugID(debugID); | ||
emitEvent('onBeginLifeCycleTimer', debugID, timerType); | ||
markBegin(debugID, timerType); | ||
beginLifeCycleTimer(debugID, timerType); | ||
}, | ||
onEndLifeCycleTimer: function (debugID, timerType) { | ||
checkDebugID(debugID); | ||
endLifeCycleTimer(debugID, timerType); | ||
markEnd(debugID, timerType); | ||
emitEvent('onEndLifeCycleTimer', debugID, timerType); | ||
}, | ||
onBeginProcessingChildContext: function () { | ||
emitEvent('onBeginProcessingChildContext'); | ||
}, | ||
onEndProcessingChildContext: function () { | ||
emitEvent('onEndProcessingChildContext'); | ||
}, | ||
onHostOperation: function (operation) { | ||
checkDebugID(operation.instanceID); | ||
emitEvent('onHostOperation', operation); | ||
}, | ||
onSetState: function () { | ||
emitEvent('onSetState'); | ||
}, | ||
onSetChildren: function (debugID, childDebugIDs) { | ||
checkDebugID(debugID); | ||
childDebugIDs.forEach(checkDebugID); | ||
emitEvent('onSetChildren', debugID, childDebugIDs); | ||
}, | ||
onBeforeMountComponent: function (debugID, element, parentDebugID) { | ||
checkDebugID(debugID); | ||
checkDebugID(parentDebugID, true); | ||
emitEvent('onBeforeMountComponent', debugID, element, parentDebugID); | ||
markBegin(debugID, 'mount'); | ||
}, | ||
onMountComponent: function (debugID) { | ||
checkDebugID(debugID); | ||
markEnd(debugID, 'mount'); | ||
emitEvent('onMountComponent', debugID); | ||
}, | ||
onBeforeUpdateComponent: function (debugID, element) { | ||
checkDebugID(debugID); | ||
emitEvent('onBeforeUpdateComponent', debugID, element); | ||
markBegin(debugID, 'update'); | ||
}, | ||
onUpdateComponent: function (debugID) { | ||
checkDebugID(debugID); | ||
markEnd(debugID, 'update'); | ||
emitEvent('onUpdateComponent', debugID); | ||
}, | ||
onBeforeUnmountComponent: function (debugID) { | ||
checkDebugID(debugID); | ||
emitEvent('onBeforeUnmountComponent', debugID); | ||
markBegin(debugID, 'unmount'); | ||
}, | ||
onUnmountComponent: function (debugID) { | ||
checkDebugID(debugID); | ||
markEnd(debugID, 'unmount'); | ||
emitEvent('onUnmountComponent', debugID); | ||
}, | ||
onTestEvent: function () { | ||
emitEvent('onTestEvent'); | ||
} | ||
}; | ||
isProfiling = false; | ||
resetMeasurements(); | ||
ReactDebugTool.removeHook(ReactHostOperationHistoryHook); | ||
}, | ||
getFlushHistory: function () { | ||
return flushHistory; | ||
}, | ||
onBeginFlush: function () { | ||
currentFlushNesting++; | ||
resetMeasurements(); | ||
pauseCurrentLifeCycleTimer(); | ||
emitEvent('onBeginFlush'); | ||
}, | ||
onEndFlush: function () { | ||
resetMeasurements(); | ||
currentFlushNesting--; | ||
resumeCurrentLifeCycleTimer(); | ||
emitEvent('onEndFlush'); | ||
}, | ||
onBeginLifeCycleTimer: function (debugID, timerType) { | ||
checkDebugID(debugID); | ||
emitEvent('onBeginLifeCycleTimer', debugID, timerType); | ||
markBegin(debugID, timerType); | ||
beginLifeCycleTimer(debugID, timerType); | ||
}, | ||
onEndLifeCycleTimer: function (debugID, timerType) { | ||
checkDebugID(debugID); | ||
endLifeCycleTimer(debugID, timerType); | ||
markEnd(debugID, timerType); | ||
emitEvent('onEndLifeCycleTimer', debugID, timerType); | ||
}, | ||
onBeginProcessingChildContext: function () { | ||
emitEvent('onBeginProcessingChildContext'); | ||
}, | ||
onEndProcessingChildContext: function () { | ||
emitEvent('onEndProcessingChildContext'); | ||
}, | ||
onHostOperation: function (operation) { | ||
checkDebugID(operation.instanceID); | ||
emitEvent('onHostOperation', operation); | ||
}, | ||
onSetState: function () { | ||
emitEvent('onSetState'); | ||
}, | ||
onSetChildren: function (debugID, childDebugIDs) { | ||
checkDebugID(debugID); | ||
childDebugIDs.forEach(checkDebugID); | ||
emitEvent('onSetChildren', debugID, childDebugIDs); | ||
}, | ||
onBeforeMountComponent: function (debugID, element, parentDebugID) { | ||
checkDebugID(debugID); | ||
checkDebugID(parentDebugID, true); | ||
emitEvent('onBeforeMountComponent', debugID, element, parentDebugID); | ||
markBegin(debugID, 'mount'); | ||
}, | ||
onMountComponent: function (debugID) { | ||
checkDebugID(debugID); | ||
markEnd(debugID, 'mount'); | ||
emitEvent('onMountComponent', debugID); | ||
}, | ||
onBeforeUpdateComponent: function (debugID, element) { | ||
checkDebugID(debugID); | ||
emitEvent('onBeforeUpdateComponent', debugID, element); | ||
markBegin(debugID, 'update'); | ||
}, | ||
onUpdateComponent: function (debugID) { | ||
checkDebugID(debugID); | ||
markEnd(debugID, 'update'); | ||
emitEvent('onUpdateComponent', debugID); | ||
}, | ||
onBeforeUnmountComponent: function (debugID) { | ||
checkDebugID(debugID); | ||
emitEvent('onBeforeUnmountComponent', debugID); | ||
markBegin(debugID, 'unmount'); | ||
}, | ||
onUnmountComponent: function (debugID) { | ||
checkDebugID(debugID); | ||
markEnd(debugID, 'unmount'); | ||
emitEvent('onUnmountComponent', debugID); | ||
}, | ||
onTestEvent: function () { | ||
emitEvent('onTestEvent'); | ||
ReactDebugTool.addHook(ReactInvalidSetStateWarningHook); | ||
ReactDebugTool.addHook(ReactComponentTreeHook); | ||
url = ExecutionEnvironment.canUseDOM && window.location.href || ''; | ||
if (/[?&]react_perf\b/.test(url)) { | ||
ReactDebugTool.beginProfiling(); | ||
} | ||
}; | ||
ReactDebugTool.addHook(ReactInvalidSetStateWarningHook); | ||
ReactDebugTool.addHook(ReactComponentTreeHook); | ||
var url = ExecutionEnvironment.canUseDOM && window.location.href || ''; | ||
if (/[?&]react_perf\b/.test(url)) { | ||
ReactDebugTool.beginProfiling(); | ||
} | ||
})(); | ||
} | ||
module.exports = ReactDebugTool; |
@@ -18,25 +18,35 @@ /** | ||
* Call a function while guarding against errors that happens within it. | ||
* Returns an error if it throws, otherwise null. | ||
* | ||
* @param {String} name of the guard to use for logging or debugging | ||
* @param {Function} func The function to invoke | ||
* @param {*} a Argument | ||
* @param {*} context The context to use when calling the function | ||
* @param {...*} args Arguments for function | ||
*/ | ||
function invokeGuardedCallback(name, func, a) { | ||
try { | ||
func(a); | ||
} catch (x) { | ||
if (caughtError === null) { | ||
caughtError = x; | ||
var ReactErrorUtils = { | ||
invokeGuardedCallback: function (name, func, context, a, b, c, d, e, f) { | ||
var funcArgs = Array.prototype.slice.call(arguments, 3); | ||
try { | ||
func.apply(context, funcArgs); | ||
} catch (error) { | ||
return error; | ||
} | ||
} | ||
} | ||
return null; | ||
}, | ||
var ReactErrorUtils = { | ||
invokeGuardedCallback: invokeGuardedCallback, | ||
/** | ||
* Invoked by ReactTestUtils.Simulate so that any errors thrown by the event | ||
* handler are sure to be rethrown by rethrowCaughtError. | ||
* Same as invokeGuardedCallback, but instead of returning an error, it stores | ||
* it in a global so it can be rethrown by `rethrowCaughtError` later. | ||
* | ||
* @param {String} name of the guard to use for logging or debugging | ||
* @param {Function} func The function to invoke | ||
* @param {*} context The context to use when calling the function | ||
* @param {...*} args Arguments for function | ||
*/ | ||
invokeGuardedCallbackWithCatch: invokeGuardedCallback, | ||
invokeGuardedCallbackAndCatchFirstError: function (name, func, context, a, b, c, d, e, f) { | ||
var error = ReactErrorUtils.invokeGuardedCallback.apply(this, arguments); | ||
if (error !== null && caughtError === null) { | ||
caughtError = error; | ||
} | ||
}, | ||
@@ -62,14 +72,32 @@ /** | ||
if (typeof window !== 'undefined' && typeof window.dispatchEvent === 'function' && typeof document !== 'undefined' && typeof document.createEvent === 'function') { | ||
var fakeNode = document.createElement('react'); | ||
ReactErrorUtils.invokeGuardedCallback = function (name, func, a) { | ||
var boundFunc = function () { | ||
func(a); | ||
(function () { | ||
var fakeNode = document.createElement('react'); | ||
var depth = 0; | ||
ReactErrorUtils.invokeGuardedCallback = function (name, func, context, a, b, c, d, e, f) { | ||
depth++; | ||
var thisDepth = depth; | ||
var funcArgs = Array.prototype.slice.call(arguments, 3); | ||
var boundFunc = function () { | ||
func.apply(context, funcArgs); | ||
}; | ||
var fakeEventError = null; | ||
var onFakeEventError = function (event) { | ||
// Don't capture nested errors | ||
if (depth === thisDepth) { | ||
fakeEventError = event.error; | ||
} | ||
}; | ||
var evtType = 'react-' + (name ? name : 'invokeguardedcallback') + '-' + depth; | ||
window.addEventListener('error', onFakeEventError); | ||
fakeNode.addEventListener(evtType, boundFunc, false); | ||
var evt = document.createEvent('Event'); | ||
evt.initEvent(evtType, false, false); | ||
fakeNode.dispatchEvent(evt); | ||
fakeNode.removeEventListener(evtType, boundFunc, false); | ||
window.removeEventListener('error', onFakeEventError); | ||
depth--; | ||
return fakeEventError; | ||
}; | ||
var evtType = 'react-' + name; | ||
fakeNode.addEventListener(evtType, boundFunc, false); | ||
var evt = document.createEvent('Event'); | ||
evt.initEvent(evtType, false, false); | ||
fakeNode.dispatchEvent(evt); | ||
fakeNode.removeEventListener(evtType, boundFunc, false); | ||
}; | ||
})(); | ||
} | ||
@@ -76,0 +104,0 @@ } |
@@ -21,3 +21,2 @@ /** | ||
var ReactEventEmitterMixin = { | ||
/** | ||
@@ -24,0 +23,0 @@ * Streams a fired top-level event to `EventPluginHub` where plugins have the |
@@ -65,3 +65,2 @@ /** | ||
var fiber = { | ||
// Instance | ||
@@ -104,3 +103,2 @@ | ||
alternate: null | ||
}; | ||
@@ -112,2 +110,3 @@ | ||
fiber._debugOwner = null; | ||
fiber._debugIsCurrentlyTiming = false; | ||
if (typeof Object.preventExtensions === 'function') { | ||
@@ -244,3 +243,3 @@ Object.preventExtensions(fiber); | ||
if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) { | ||
info += ' You likely forgot to export your component from the file ' + 'it\'s defined in.'; | ||
info += ' You likely forgot to export your component from the file ' + "it's defined in."; | ||
} | ||
@@ -247,0 +246,0 @@ var ownerName = debugOwner ? getComponentName(debugOwner) : null; |
@@ -14,4 +14,2 @@ /** | ||
var _prodInvariant = require('./reactProdInvariant'); | ||
var _require = require('./ReactChildFiber'), | ||
@@ -64,3 +62,8 @@ mountChildFibersInPlace = _require.mountChildFibersInPlace, | ||
var ReactDebugCurrentFiber = require('./ReactDebugCurrentFiber'); | ||
var _require6 = require('./ReactDebugFiberPerf'), | ||
cancelWorkTimer = _require6.cancelWorkTimer; | ||
var warning = require('fbjs/lib/warning'); | ||
var warnedAboutStatelessRefs = {}; | ||
@@ -70,3 +73,5 @@ } | ||
module.exports = function (config, hostContext, scheduleUpdate, getPriorityContext) { | ||
var shouldSetTextContent = config.shouldSetTextContent; | ||
var shouldSetTextContent = config.shouldSetTextContent, | ||
useSyncScheduling = config.useSyncScheduling, | ||
shouldDeprioritizeSubtree = config.shouldDeprioritizeSubtree; | ||
var pushHostContext = hostContext.pushHostContext, | ||
@@ -197,3 +202,5 @@ pushHostContainer = hostContext.pushHostContainer; | ||
ReactCurrentOwner.current = workInProgress; | ||
ReactDebugCurrentFiber.phase = 'render'; | ||
nextChildren = fn(nextProps, context); | ||
ReactDebugCurrentFiber.phase = null; | ||
} else { | ||
@@ -242,3 +249,10 @@ nextChildren = fn(nextProps, context); | ||
ReactCurrentOwner.current = workInProgress; | ||
var nextChildren = instance.render(); | ||
var nextChildren = void 0; | ||
if (process.env.NODE_ENV !== 'production') { | ||
ReactDebugCurrentFiber.phase = 'render'; | ||
nextChildren = instance.render(); | ||
ReactDebugCurrentFiber.phase = null; | ||
} else { | ||
nextChildren = instance.render(); | ||
} | ||
reconcileChildren(current, workInProgress, nextChildren); | ||
@@ -300,3 +314,3 @@ // Memoize props and state using the values we just used to render. | ||
} else if (nextProps === null || memoizedProps === nextProps) { | ||
if (memoizedProps.hidden && workInProgress.pendingWorkPriority !== OffscreenPriority) { | ||
if (!useSyncScheduling && shouldDeprioritizeSubtree(workInProgress.type, memoizedProps) && workInProgress.pendingWorkPriority !== OffscreenPriority) { | ||
// This subtree still has work, but it should be deprioritized so we need | ||
@@ -338,3 +352,3 @@ // to bail out and not do any work yet. | ||
if (nextProps.hidden && workInProgress.pendingWorkPriority !== OffscreenPriority) { | ||
if (!useSyncScheduling && shouldDeprioritizeSubtree(workInProgress.type, nextProps) && workInProgress.pendingWorkPriority !== OffscreenPriority) { | ||
// If this host component is hidden, we can bail out on the children. | ||
@@ -548,2 +562,6 @@ // We'll rerender the children later at the lower priority. | ||
function bailoutOnAlreadyFinishedWork(current, workInProgress) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
cancelWorkTimer(workInProgress); | ||
} | ||
var priorityLevel = workInProgress.pendingWorkPriority; | ||
@@ -576,2 +594,6 @@ // TODO: We should ideally be able to bail out early if the children have no | ||
function bailoutOnLowPriority(current, workInProgress) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
cancelWorkTimer(workInProgress); | ||
} | ||
// TODO: Handle HostComponent tags here as well and call pushHostContext()? | ||
@@ -578,0 +600,0 @@ // See PR 8590 discussion for context |
@@ -35,3 +35,2 @@ /** | ||
var _require5 = require('./ReactFiberTreeReflection'), | ||
getComponentName = _require5.getComponentName, | ||
isMounted = _require5.isMounted; | ||
@@ -41,2 +40,3 @@ | ||
var emptyObject = require('fbjs/lib/emptyObject'); | ||
var getComponentName = require('./getComponentName'); | ||
var shallowEqual = require('fbjs/lib/shallowEqual'); | ||
@@ -48,5 +48,9 @@ var invariant = require('fbjs/lib/invariant'); | ||
if (process.env.NODE_ENV !== 'production') { | ||
var _require6 = require('./ReactDebugFiberPerf'), | ||
startPhaseTimer = _require6.startPhaseTimer, | ||
stopPhaseTimer = _require6.stopPhaseTimer; | ||
var warning = require('fbjs/lib/warning'); | ||
var warnOnInvalidCallback = function (callback, callerName) { | ||
process.env.NODE_ENV !== 'production' ? warning(callback === null || typeof callback === 'function', '%s(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callerName, String(callback)) : void 0; | ||
process.env.NODE_ENV !== 'production' ? warning(callback === null || typeof callback === 'function', '%s(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callerName, callback) : void 0; | ||
}; | ||
@@ -56,3 +60,2 @@ } | ||
module.exports = function (scheduleUpdate, getPriorityContext, memoizeProps, memoizeState) { | ||
// Class component state updater | ||
@@ -101,6 +104,12 @@ var updater = { | ||
if (typeof instance.shouldComponentUpdate === 'function') { | ||
if (process.env.NODE_ENV !== 'production') { | ||
startPhaseTimer(workInProgress, 'shouldComponentUpdate'); | ||
} | ||
var shouldUpdate = instance.shouldComponentUpdate(newProps, newState, newContext); | ||
if (process.env.NODE_ENV !== 'production') { | ||
stopPhaseTimer(); | ||
} | ||
if (process.env.NODE_ENV !== 'production') { | ||
process.env.NODE_ENV !== 'production' ? warning(shouldUpdate !== undefined, '%s.shouldComponentUpdate(): Returned undefined instead of a ' + 'boolean value. Make sure to return true or false.', getComponentName(workInProgress)) : void 0; | ||
process.env.NODE_ENV !== 'production' ? warning(shouldUpdate !== undefined, '%s.shouldComponentUpdate(): Returned undefined instead of a ' + 'boolean value. Make sure to return true or false.', getComponentName(workInProgress) || 'Unknown') : void 0; | ||
} | ||
@@ -140,3 +149,3 @@ | ||
var hasMutatedProps = instance.props !== workInProgress.pendingProps; | ||
process.env.NODE_ENV !== 'production' ? warning(instance.props === undefined || !hasMutatedProps, '%s(...): When calling super() in `%s`, make sure to pass ' + 'up the same props that your component\'s constructor was passed.', name, name) : void 0; | ||
process.env.NODE_ENV !== 'production' ? warning(instance.props === undefined || !hasMutatedProps, '%s(...): When calling super() in `%s`, make sure to pass ' + "up the same props that your component's constructor was passed.", name, name) : void 0; | ||
} | ||
@@ -153,16 +162,2 @@ | ||
function markUpdate(workInProgress) { | ||
workInProgress.effectTag |= Update; | ||
} | ||
function markUpdateIfAlreadyInProgress(current, workInProgress) { | ||
// If an update was already in progress, we should schedule an Update | ||
// effect even though we're bailing out, so that cWU/cDU are called. | ||
if (current !== null) { | ||
if (workInProgress.memoizedProps !== current.memoizedProps || workInProgress.memoizedState !== current.memoizedState) { | ||
markUpdate(workInProgress); | ||
} | ||
} | ||
} | ||
function resetInputPointers(workInProgress, instance) { | ||
@@ -201,3 +196,2 @@ instance.props = workInProgress.memoizedProps; | ||
function mountClassInstance(workInProgress, priorityLevel) { | ||
markUpdate(workInProgress); | ||
var instance = workInProgress.stateNode; | ||
@@ -217,3 +211,9 @@ var state = instance.state || null; | ||
if (typeof instance.componentWillMount === 'function') { | ||
if (process.env.NODE_ENV !== 'production') { | ||
startPhaseTimer(workInProgress, 'componentWillMount'); | ||
} | ||
instance.componentWillMount(); | ||
if (process.env.NODE_ENV !== 'production') { | ||
stopPhaseTimer(); | ||
} | ||
// If we had additional state updates during this life-cycle, let's | ||
@@ -226,2 +226,5 @@ // process them now. | ||
} | ||
if (typeof instance.componentDidMount === 'function') { | ||
workInProgress.effectTag |= Update; | ||
} | ||
} | ||
@@ -232,3 +235,2 @@ | ||
function resumeMountClassInstance(workInProgress, priorityLevel) { | ||
markUpdate(workInProgress); | ||
var instance = workInProgress.stateNode; | ||
@@ -269,3 +271,9 @@ resetInputPointers(workInProgress, instance); | ||
if (typeof newInstance.componentWillMount === 'function') { | ||
if (process.env.NODE_ENV !== 'production') { | ||
startPhaseTimer(workInProgress, 'componentWillMount'); | ||
} | ||
newInstance.componentWillMount(); | ||
if (process.env.NODE_ENV !== 'production') { | ||
stopPhaseTimer(); | ||
} | ||
} | ||
@@ -279,2 +287,5 @@ // If we had additional state updates, process them now. | ||
} | ||
if (typeof instance.componentDidMount === 'function') { | ||
workInProgress.effectTag |= Update; | ||
} | ||
return true; | ||
@@ -306,7 +317,13 @@ } | ||
if (typeof instance.componentWillReceiveProps === 'function') { | ||
if (process.env.NODE_ENV !== 'production') { | ||
startPhaseTimer(workInProgress, 'componentWillReceiveProps'); | ||
} | ||
instance.componentWillReceiveProps(newProps, newContext); | ||
if (process.env.NODE_ENV !== 'production') { | ||
stopPhaseTimer(); | ||
} | ||
if (instance.state !== workInProgress.memoizedState) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
process.env.NODE_ENV !== 'production' ? warning(false, '%s.componentWillReceiveProps(): Assigning directly to ' + 'this.state is deprecated (except inside a component\'s ' + 'constructor). Use setState instead.', getComponentName(workInProgress)) : void 0; | ||
process.env.NODE_ENV !== 'production' ? warning(false, '%s.componentWillReceiveProps(): Assigning directly to ' + "this.state is deprecated (except inside a component's " + 'constructor). Use setState instead.', getComponentName(workInProgress)) : void 0; | ||
} | ||
@@ -330,3 +347,9 @@ updater.enqueueReplaceState(instance, instance.state, null); | ||
if (oldProps === newProps && oldState === newState && !hasContextChanged() && !(updateQueue !== null && updateQueue.hasForceUpdate)) { | ||
markUpdateIfAlreadyInProgress(current, workInProgress); | ||
// If an update was already in progress, we should schedule an Update | ||
// effect even though we're bailing out, so that cWU/cDU are called. | ||
if (typeof instance.componentDidUpdate === 'function') { | ||
if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) { | ||
workInProgress.effectTag |= Update; | ||
} | ||
} | ||
return false; | ||
@@ -338,8 +361,22 @@ } | ||
if (shouldUpdate) { | ||
markUpdate(workInProgress); | ||
if (typeof instance.componentWillUpdate === 'function') { | ||
if (process.env.NODE_ENV !== 'production') { | ||
startPhaseTimer(workInProgress, 'componentWillUpdate'); | ||
} | ||
instance.componentWillUpdate(newProps, newState, newContext); | ||
if (process.env.NODE_ENV !== 'production') { | ||
stopPhaseTimer(); | ||
} | ||
} | ||
if (typeof instance.componentDidUpdate === 'function') { | ||
workInProgress.effectTag |= Update; | ||
} | ||
} else { | ||
markUpdateIfAlreadyInProgress(current, workInProgress); | ||
// If an update was already in progress, we should schedule an Update | ||
// effect even though we're bailing out, so that cWU/cDU are called. | ||
if (typeof instance.componentDidUpdate === 'function') { | ||
if (oldProps !== current.memoizedProps || oldState !== current.memoizedState) { | ||
workInProgress.effectTag |= Update; | ||
} | ||
} | ||
@@ -346,0 +383,0 @@ // If shouldComponentUpdate returned false, we should still update the |
@@ -14,4 +14,2 @@ /** | ||
var _prodInvariant = require('./reactProdInvariant'); | ||
var ReactTypeOfWork = require('./ReactTypeOfWork'); | ||
@@ -31,10 +29,19 @@ var ClassComponent = ReactTypeOfWork.ClassComponent, | ||
var _require3 = require('./ReactTypeOfSideEffect'), | ||
Placement = _require3.Placement, | ||
Update = _require3.Update, | ||
Callback = _require3.Callback, | ||
ContentReset = _require3.ContentReset; | ||
var _require3 = require('./ReactErrorUtils'), | ||
invokeGuardedCallback = _require3.invokeGuardedCallback; | ||
var _require4 = require('./ReactTypeOfSideEffect'), | ||
Placement = _require4.Placement, | ||
Update = _require4.Update, | ||
Callback = _require4.Callback, | ||
ContentReset = _require4.ContentReset; | ||
var invariant = require('fbjs/lib/invariant'); | ||
if (process.env.NODE_ENV !== 'production') { | ||
var _require5 = require('./ReactDebugFiberPerf'), | ||
startPhaseTimer = _require5.startPhaseTimer, | ||
stopPhaseTimer = _require5.stopPhaseTimer; | ||
} | ||
module.exports = function (config, captureError) { | ||
@@ -50,30 +57,41 @@ var commitMount = config.commitMount, | ||
// Capture errors so they don't interrupt unmounting. | ||
function safelyCallComponentWillUnmount(current, instance) { | ||
try { | ||
if (process.env.NODE_ENV !== 'production') { | ||
var callComponentWillUnmountWithTimerInDev = function (current, instance) { | ||
startPhaseTimer(current, 'componentWillUnmount'); | ||
instance.componentWillUnmount(); | ||
} catch (error) { | ||
captureError(current, error); | ||
} | ||
stopPhaseTimer(); | ||
}; | ||
} | ||
// Capture errors so they don't interrupt unmounting. | ||
function safelyDetachRef(current) { | ||
try { | ||
var ref = current.ref; | ||
if (ref !== null) { | ||
ref(null); | ||
function safelyCallComponentWillUnmount(current, instance) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
var unmountError = invokeGuardedCallback(null, callComponentWillUnmountWithTimerInDev, null, current, instance); | ||
if (unmountError) { | ||
captureError(current, unmountError); | ||
} | ||
} catch (error) { | ||
captureError(current, error); | ||
} else { | ||
try { | ||
instance.componentWillUnmount(); | ||
} catch (unmountError) { | ||
captureError(current, unmountError); | ||
} | ||
} | ||
} | ||
// Only called during update. It's ok to throw. | ||
function detachRefIfNeeded(current, finishedWork) { | ||
if (current) { | ||
var currentRef = current.ref; | ||
if (currentRef !== null && currentRef !== finishedWork.ref) { | ||
currentRef(null); | ||
function safelyDetachRef(current) { | ||
var ref = current.ref; | ||
if (ref !== null) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
var refError = invokeGuardedCallback(null, ref, null, null); | ||
if (refError !== null) { | ||
captureError(current, refError); | ||
} | ||
} else { | ||
try { | ||
ref(null); | ||
} catch (refError) { | ||
captureError(current, refError); | ||
} | ||
} | ||
@@ -353,3 +371,2 @@ } | ||
{ | ||
detachRefIfNeeded(current, finishedWork); | ||
return; | ||
@@ -372,3 +389,2 @@ } | ||
} | ||
detachRefIfNeeded(current, finishedWork); | ||
return; | ||
@@ -407,11 +423,19 @@ } | ||
if (current === null) { | ||
if (typeof instance.componentDidMount === 'function') { | ||
instance.componentDidMount(); | ||
if (process.env.NODE_ENV !== 'production') { | ||
startPhaseTimer(finishedWork, 'componentDidMount'); | ||
} | ||
instance.componentDidMount(); | ||
if (process.env.NODE_ENV !== 'production') { | ||
stopPhaseTimer(); | ||
} | ||
} else { | ||
if (typeof instance.componentDidUpdate === 'function') { | ||
var prevProps = current.memoizedProps; | ||
var prevState = current.memoizedState; | ||
instance.componentDidUpdate(prevProps, prevState); | ||
var prevProps = current.memoizedProps; | ||
var prevState = current.memoizedState; | ||
if (process.env.NODE_ENV !== 'production') { | ||
startPhaseTimer(finishedWork, 'componentDidUpdate'); | ||
} | ||
instance.componentDidUpdate(prevProps, prevState); | ||
if (process.env.NODE_ENV !== 'production') { | ||
stopPhaseTimer(); | ||
} | ||
} | ||
@@ -466,6 +490,3 @@ } | ||
function commitRef(finishedWork) { | ||
if (finishedWork.tag !== ClassComponent && finishedWork.tag !== HostComponent) { | ||
return; | ||
} | ||
function commitAttachRef(finishedWork) { | ||
var ref = finishedWork.ref; | ||
@@ -478,2 +499,9 @@ if (ref !== null) { | ||
function commitDetachRef(current) { | ||
var currentRef = current.ref; | ||
if (currentRef !== null) { | ||
currentRef(null); | ||
} | ||
} | ||
return { | ||
@@ -484,4 +512,5 @@ commitPlacement: commitPlacement, | ||
commitLifeCycles: commitLifeCycles, | ||
commitRef: commitRef | ||
commitAttachRef: commitAttachRef, | ||
commitDetachRef: commitDetachRef | ||
}; | ||
}; |
@@ -14,4 +14,2 @@ /** | ||
var _prodInvariant = require('./reactProdInvariant'); | ||
var _require = require('./ReactChildFiber'), | ||
@@ -76,2 +74,6 @@ reconcileChildFibers = _require.reconcileChildFibers; | ||
function markRef(workInProgress) { | ||
workInProgress.effectTag |= Ref; | ||
} | ||
function appendAllYields(yields, workInProgress) { | ||
@@ -206,5 +208,8 @@ var node = workInProgress.stateNode; | ||
// is a new ref we mark this as an update. | ||
if (updatePayload || current.ref !== workInProgress.ref) { | ||
if (updatePayload) { | ||
markUpdate(workInProgress); | ||
} | ||
if (current.ref !== workInProgress.ref) { | ||
markRef(workInProgress); | ||
} | ||
} else { | ||
@@ -236,3 +241,3 @@ if (!newProps) { | ||
// If there is a ref on a host node we need to schedule a callback | ||
workInProgress.effectTag |= Ref; | ||
markRef(workInProgress); | ||
} | ||
@@ -239,0 +244,0 @@ } |
@@ -20,2 +20,3 @@ /** | ||
var emptyObject = require('fbjs/lib/emptyObject'); | ||
var getComponentName = require('./getComponentName'); | ||
var invariant = require('fbjs/lib/invariant'); | ||
@@ -25,3 +26,2 @@ var warning = require('fbjs/lib/warning'); | ||
var _require = require('./ReactFiberTreeReflection'), | ||
getComponentName = _require.getComponentName, | ||
isFiberMounted = _require.isFiberMounted; | ||
@@ -41,2 +41,8 @@ | ||
var ReactDebugCurrentFrame = require('react/lib/ReactDebugCurrentFrame'); | ||
var ReactDebugCurrentFiber = require('./ReactDebugCurrentFiber'); | ||
var _require4 = require('./ReactDebugFiberPerf'), | ||
startPhaseTimer = _require4.startPhaseTimer, | ||
stopPhaseTimer = _require4.stopPhaseTimer; | ||
var warnedAboutMissingGetChildContext = {}; | ||
@@ -95,3 +101,3 @@ } | ||
if (process.env.NODE_ENV !== 'production') { | ||
var name = getComponentName(workInProgress); | ||
var name = getComponentName(workInProgress) || 'Unknown'; | ||
ReactDebugCurrentFrame.current = workInProgress; | ||
@@ -150,3 +156,3 @@ checkReactTypeSpec(contextTypes, context, 'context', name); | ||
if (process.env.NODE_ENV !== 'production') { | ||
var componentName = getComponentName(fiber); | ||
var componentName = getComponentName(fiber) || 'Unknown'; | ||
@@ -161,8 +167,17 @@ if (!warnedAboutMissingGetChildContext[componentName]) { | ||
var childContext = instance.getChildContext(); | ||
var childContext = void 0; | ||
if (process.env.NODE_ENV !== 'production') { | ||
ReactDebugCurrentFiber.phase = 'getChildContext'; | ||
startPhaseTimer(fiber, 'getChildContext'); | ||
childContext = instance.getChildContext(); | ||
stopPhaseTimer(); | ||
ReactDebugCurrentFiber.phase = null; | ||
} else { | ||
childContext = instance.getChildContext(); | ||
} | ||
for (var contextKey in childContext) { | ||
!(contextKey in childContextTypes) ? process.env.NODE_ENV !== 'production' ? invariant(false, '%s.getChildContext(): key "%s" is not defined in childContextTypes.', getComponentName(fiber), contextKey) : _prodInvariant('108', getComponentName(fiber), contextKey) : void 0; | ||
!(contextKey in childContextTypes) ? process.env.NODE_ENV !== 'production' ? invariant(false, '%s.getChildContext(): key "%s" is not defined in childContextTypes.', getComponentName(fiber) || 'Unknown', contextKey) : _prodInvariant('108', getComponentName(fiber) || 'Unknown', contextKey) : void 0; | ||
} | ||
if (process.env.NODE_ENV !== 'production') { | ||
var name = getComponentName(fiber); | ||
var name = getComponentName(fiber) || 'Unknown'; | ||
// We can only provide accurate element stacks if we pass work-in-progress tree | ||
@@ -178,2 +193,3 @@ // during the begin or complete phase. However currently this function is also | ||
} | ||
return _extends({}, parentContext, childContext); | ||
@@ -180,0 +196,0 @@ } |
@@ -21,39 +21,41 @@ /** | ||
if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && __REACT_DEVTOOLS_GLOBAL_HOOK__.supportsFiber) { | ||
var inject = __REACT_DEVTOOLS_GLOBAL_HOOK__.inject, | ||
onCommitFiberRoot = __REACT_DEVTOOLS_GLOBAL_HOOK__.onCommitFiberRoot, | ||
onCommitFiberUnmount = __REACT_DEVTOOLS_GLOBAL_HOOK__.onCommitFiberUnmount; | ||
(function () { | ||
var inject = __REACT_DEVTOOLS_GLOBAL_HOOK__.inject, | ||
onCommitFiberRoot = __REACT_DEVTOOLS_GLOBAL_HOOK__.onCommitFiberRoot, | ||
onCommitFiberUnmount = __REACT_DEVTOOLS_GLOBAL_HOOK__.onCommitFiberUnmount; | ||
injectInternals = function (internals) { | ||
process.env.NODE_ENV !== 'production' ? warning(rendererID == null, 'Cannot inject into DevTools twice.') : void 0; | ||
rendererID = inject(internals); | ||
}; | ||
injectInternals = function (internals) { | ||
process.env.NODE_ENV !== 'production' ? warning(rendererID == null, 'Cannot inject into DevTools twice.') : void 0; | ||
rendererID = inject(internals); | ||
}; | ||
onCommitRoot = function (root) { | ||
if (rendererID == null) { | ||
return; | ||
} | ||
try { | ||
onCommitFiberRoot(rendererID, root); | ||
} catch (err) { | ||
// Catch all errors because it is unsafe to throw in the commit phase. | ||
if (process.env.NODE_ENV !== 'production') { | ||
process.env.NODE_ENV !== 'production' ? warning(false, 'React DevTools encountered an error: %s', err) : void 0; | ||
onCommitRoot = function (root) { | ||
if (rendererID == null) { | ||
return; | ||
} | ||
} | ||
}; | ||
try { | ||
onCommitFiberRoot(rendererID, root); | ||
} catch (err) { | ||
// Catch all errors because it is unsafe to throw in the commit phase. | ||
if (process.env.NODE_ENV !== 'production') { | ||
process.env.NODE_ENV !== 'production' ? warning(false, 'React DevTools encountered an error: %s', err) : void 0; | ||
} | ||
} | ||
}; | ||
onCommitUnmount = function (fiber) { | ||
if (rendererID == null) { | ||
return; | ||
} | ||
try { | ||
onCommitFiberUnmount(rendererID, fiber); | ||
} catch (err) { | ||
// Catch all errors because it is unsafe to throw in the commit phase. | ||
if (process.env.NODE_ENV !== 'production') { | ||
process.env.NODE_ENV !== 'production' ? warning(false, 'React DevTools encountered an error: %s', err) : void 0; | ||
onCommitUnmount = function (fiber) { | ||
if (rendererID == null) { | ||
return; | ||
} | ||
} | ||
}; | ||
try { | ||
onCommitFiberUnmount(rendererID, fiber); | ||
} catch (err) { | ||
// Catch all errors because it is unsafe to throw in the commit phase. | ||
if (process.env.NODE_ENV !== 'production') { | ||
process.env.NODE_ENV !== 'production' ? warning(false, 'React DevTools encountered an error: %s', err) : void 0; | ||
} | ||
} | ||
}; | ||
})(); | ||
} | ||
@@ -60,0 +62,0 @@ |
@@ -14,4 +14,2 @@ /** | ||
var _prodInvariant = require('./reactProdInvariant'); | ||
var emptyObject = require('fbjs/lib/emptyObject'); | ||
@@ -18,0 +16,0 @@ |
@@ -30,2 +30,4 @@ /** | ||
var ReactFiberInstrumentation = require('./ReactFiberInstrumentation'); | ||
var ReactDebugCurrentFiber = require('./ReactDebugCurrentFiber'); | ||
var getComponentName = require('./getComponentName'); | ||
} | ||
@@ -54,2 +56,8 @@ | ||
function scheduleTopLevelUpdate(current, element, callback) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
if (ReactDebugCurrentFiber.phase === 'render' && ReactDebugCurrentFiber.current !== null) { | ||
process.env.NODE_ENV !== 'production' ? warning(false, 'Render methods should be a pure function of props and state; ' + 'triggering nested component updates from render is not allowed. ' + 'If necessary, trigger nested updates in componentDidUpdate.\n\n' + 'Check the render method of %s.', getComponentName(ReactDebugCurrentFiber.current) || 'Unknown') : void 0; | ||
} | ||
} | ||
var priorityLevel = getPriorityContext(); | ||
@@ -59,3 +67,3 @@ var nextState = { element: element }; | ||
if (process.env.NODE_ENV !== 'production') { | ||
process.env.NODE_ENV !== 'production' ? warning(callback === null || typeof callback === 'function', 'render(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', String(callback)) : void 0; | ||
process.env.NODE_ENV !== 'production' ? warning(callback === null || typeof callback === 'function', 'render(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callback) : void 0; | ||
} | ||
@@ -62,0 +70,0 @@ addTopLevelUpdate(current, nextState, callback, priorityLevel); |
@@ -14,4 +14,2 @@ /** | ||
var _prodInvariant = require('./reactProdInvariant'); | ||
var _require = require('./ReactFiberContext'), | ||
@@ -23,3 +21,3 @@ popContextProvider = _require.popContextProvider; | ||
var _require3 = require('react/lib/ReactComponentTreeHook'), | ||
var _require3 = require('./ReactFiberComponentTreeHook'), | ||
getStackAddendumByWorkInProgressFiber = _require3.getStackAddendumByWorkInProgressFiber; | ||
@@ -30,2 +28,5 @@ | ||
var _require5 = require('./ReactErrorUtils'), | ||
invokeGuardedCallback = _require5.invokeGuardedCallback; | ||
var ReactFiberBeginWork = require('./ReactFiberBeginWork'); | ||
@@ -39,39 +40,39 @@ var ReactFiberCompleteWork = require('./ReactFiberCompleteWork'); | ||
var _require5 = require('./ReactFiber'), | ||
cloneFiber = _require5.cloneFiber; | ||
var _require6 = require('./ReactFiber'), | ||
cloneFiber = _require6.cloneFiber; | ||
var _require6 = require('./ReactFiberDevToolsHook'), | ||
onCommitRoot = _require6.onCommitRoot; | ||
var _require7 = require('./ReactFiberDevToolsHook'), | ||
onCommitRoot = _require7.onCommitRoot; | ||
var _require7 = require('./ReactPriorityLevel'), | ||
NoWork = _require7.NoWork, | ||
SynchronousPriority = _require7.SynchronousPriority, | ||
TaskPriority = _require7.TaskPriority, | ||
AnimationPriority = _require7.AnimationPriority, | ||
HighPriority = _require7.HighPriority, | ||
LowPriority = _require7.LowPriority, | ||
OffscreenPriority = _require7.OffscreenPriority; | ||
var _require8 = require('./ReactPriorityLevel'), | ||
NoWork = _require8.NoWork, | ||
SynchronousPriority = _require8.SynchronousPriority, | ||
TaskPriority = _require8.TaskPriority, | ||
AnimationPriority = _require8.AnimationPriority, | ||
HighPriority = _require8.HighPriority, | ||
LowPriority = _require8.LowPriority, | ||
OffscreenPriority = _require8.OffscreenPriority; | ||
var _require8 = require('./ReactTypeOfSideEffect'), | ||
NoEffect = _require8.NoEffect, | ||
Placement = _require8.Placement, | ||
Update = _require8.Update, | ||
PlacementAndUpdate = _require8.PlacementAndUpdate, | ||
Deletion = _require8.Deletion, | ||
ContentReset = _require8.ContentReset, | ||
Callback = _require8.Callback, | ||
Err = _require8.Err, | ||
Ref = _require8.Ref; | ||
var _require9 = require('./ReactTypeOfSideEffect'), | ||
NoEffect = _require9.NoEffect, | ||
Placement = _require9.Placement, | ||
Update = _require9.Update, | ||
PlacementAndUpdate = _require9.PlacementAndUpdate, | ||
Deletion = _require9.Deletion, | ||
ContentReset = _require9.ContentReset, | ||
Callback = _require9.Callback, | ||
Err = _require9.Err, | ||
Ref = _require9.Ref; | ||
var _require9 = require('./ReactTypeOfWork'), | ||
HostRoot = _require9.HostRoot, | ||
HostComponent = _require9.HostComponent, | ||
HostPortal = _require9.HostPortal, | ||
ClassComponent = _require9.ClassComponent; | ||
var _require10 = require('./ReactTypeOfWork'), | ||
HostRoot = _require10.HostRoot, | ||
HostComponent = _require10.HostComponent, | ||
HostPortal = _require10.HostPortal, | ||
ClassComponent = _require10.ClassComponent; | ||
var _require10 = require('./ReactFiberUpdateQueue'), | ||
getPendingPriority = _require10.getPendingPriority; | ||
var _require11 = require('./ReactFiberUpdateQueue'), | ||
getPendingPriority = _require11.getPendingPriority; | ||
var _require11 = require('./ReactFiberContext'), | ||
resetContext = _require11.resetContext; | ||
var _require12 = require('./ReactFiberContext'), | ||
resetContext = _require12.resetContext; | ||
@@ -85,2 +86,16 @@ var invariant = require('fbjs/lib/invariant'); | ||
var _require13 = require('./ReactDebugFiberPerf'), | ||
recordEffect = _require13.recordEffect, | ||
recordScheduleUpdate = _require13.recordScheduleUpdate, | ||
startWorkTimer = _require13.startWorkTimer, | ||
stopWorkTimer = _require13.stopWorkTimer, | ||
startWorkLoopTimer = _require13.startWorkLoopTimer, | ||
stopWorkLoopTimer = _require13.stopWorkLoopTimer, | ||
startCommitTimer = _require13.startCommitTimer, | ||
stopCommitTimer = _require13.stopCommitTimer, | ||
startCommitHostEffectsTimer = _require13.startCommitHostEffectsTimer, | ||
stopCommitHostEffectsTimer = _require13.stopCommitHostEffectsTimer, | ||
startCommitLifeCyclesTimer = _require13.startCommitLifeCyclesTimer, | ||
stopCommitLifeCyclesTimer = _require13.stopCommitLifeCyclesTimer; | ||
var warnAboutUpdateOnUnmounted = function (instance) { | ||
@@ -90,2 +105,13 @@ var ctor = instance.constructor; | ||
}; | ||
var warnAboutInvalidUpdates = function (instance) { | ||
switch (ReactDebugCurrentFiber.phase) { | ||
case 'getChildContext': | ||
process.env.NODE_ENV !== 'production' ? warning(false, 'setState(...): Cannot call setState() inside getChildContext()') : void 0; | ||
break; | ||
case 'render': | ||
process.env.NODE_ENV !== 'production' ? warning(false, 'Cannot update during an existing state transition (such as within ' + "`render` or another component's constructor). Render methods should " + 'be a pure function of props and state; constructor side-effects are ' + 'an anti-pattern, but can be moved to `componentWillMount`.') : void 0; | ||
break; | ||
} | ||
}; | ||
} | ||
@@ -113,3 +139,4 @@ | ||
commitLifeCycles = _ReactFiberCommitWork.commitLifeCycles, | ||
commitRef = _ReactFiberCommitWork.commitRef; | ||
commitAttachRef = _ReactFiberCommitWork.commitAttachRef, | ||
commitDetachRef = _ReactFiberCommitWork.commitDetachRef; | ||
@@ -134,2 +161,5 @@ var hostScheduleAnimationCallback = config.scheduleAnimationCallback, | ||
// Keeps track of whether the current deadline has expired. | ||
var deadlineHasExpired = false; | ||
// Keeps track of whether we should should batch sync updates. | ||
@@ -250,8 +280,17 @@ var isBatchingUpdates = false; | ||
ReactDebugCurrentFiber.current = nextEffect; | ||
recordEffect(); | ||
} | ||
if (nextEffect.effectTag & ContentReset) { | ||
var effectTag = nextEffect.effectTag; | ||
if (effectTag & ContentReset) { | ||
config.resetTextContent(nextEffect.stateNode); | ||
} | ||
if (effectTag & Ref) { | ||
var current = nextEffect.alternate; | ||
if (current !== null) { | ||
commitDetachRef(current); | ||
} | ||
} | ||
// The following switch statement is only concerned about placement, | ||
@@ -261,3 +300,3 @@ // updates, and deletions. To avoid needing to add a case for every | ||
// effect tag and switch on that value. | ||
var primaryEffectTag = nextEffect.effectTag & ~(Callback | Err | ContentReset | Ref); | ||
var primaryEffectTag = effectTag & ~(Callback | Err | ContentReset | Ref); | ||
switch (primaryEffectTag) { | ||
@@ -284,4 +323,4 @@ case Placement: | ||
// Update | ||
var current = nextEffect.alternate; | ||
commitWork(current, nextEffect); | ||
var _current = nextEffect.alternate; | ||
commitWork(_current, nextEffect); | ||
break; | ||
@@ -291,4 +330,4 @@ } | ||
{ | ||
var _current = nextEffect.alternate; | ||
commitWork(_current, nextEffect); | ||
var _current2 = nextEffect.alternate; | ||
commitWork(_current2, nextEffect); | ||
break; | ||
@@ -314,13 +353,24 @@ } | ||
while (nextEffect !== null) { | ||
var current = nextEffect.alternate; | ||
var effectTag = nextEffect.effectTag; | ||
// Use Task priority for lifecycle updates | ||
if (nextEffect.effectTag & (Update | Callback)) { | ||
if (effectTag & (Update | Callback)) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
recordEffect(); | ||
} | ||
var current = nextEffect.alternate; | ||
commitLifeCycles(current, nextEffect); | ||
} | ||
if (nextEffect.effectTag & Ref) { | ||
commitRef(nextEffect); | ||
if (effectTag & Ref) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
recordEffect(); | ||
} | ||
commitAttachRef(nextEffect); | ||
} | ||
if (nextEffect.effectTag & Err) { | ||
if (effectTag & Err) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
recordEffect(); | ||
} | ||
commitErrorHandling(nextEffect); | ||
@@ -347,2 +397,5 @@ } | ||
isCommitting = true; | ||
if (process.env.NODE_ENV !== 'production') { | ||
startCommitTimer(); | ||
} | ||
@@ -383,8 +436,19 @@ pendingCommit = null; | ||
nextEffect = firstEffect; | ||
if (process.env.NODE_ENV !== 'production') { | ||
startCommitHostEffectsTimer(); | ||
} | ||
while (nextEffect !== null) { | ||
try { | ||
commitAllHostEffects(finishedWork); | ||
} catch (error) { | ||
var _error = null; | ||
if (process.env.NODE_ENV !== 'production') { | ||
_error = invokeGuardedCallback(null, commitAllHostEffects, null, finishedWork); | ||
} else { | ||
try { | ||
commitAllHostEffects(finishedWork); | ||
} catch (e) { | ||
_error = e; | ||
} | ||
} | ||
if (_error !== null) { | ||
invariant(nextEffect !== null, 'Should have next effect. This error is likely caused by a bug ' + 'in React. Please file an issue.'); | ||
captureError(nextEffect, error); | ||
captureError(nextEffect, _error); | ||
// Clean-up | ||
@@ -396,2 +460,5 @@ if (nextEffect !== null) { | ||
} | ||
if (process.env.NODE_ENV !== 'production') { | ||
stopCommitHostEffectsTimer(); | ||
} | ||
@@ -411,8 +478,19 @@ resetAfterCommit(commitInfo); | ||
nextEffect = firstEffect; | ||
if (process.env.NODE_ENV !== 'production') { | ||
startCommitLifeCyclesTimer(); | ||
} | ||
while (nextEffect !== null) { | ||
try { | ||
commitAllLifeCycles(finishedWork, nextEffect); | ||
} catch (error) { | ||
var _error2 = null; | ||
if (process.env.NODE_ENV !== 'production') { | ||
_error2 = invokeGuardedCallback(null, commitAllLifeCycles, null, finishedWork); | ||
} else { | ||
try { | ||
commitAllLifeCycles(finishedWork); | ||
} catch (e) { | ||
_error2 = e; | ||
} | ||
} | ||
if (_error2 !== null) { | ||
invariant(nextEffect !== null, 'Should have next effect. This error is likely caused by a bug ' + 'in React. Please file an issue.'); | ||
captureError(nextEffect, error); | ||
captureError(nextEffect, _error2); | ||
if (nextEffect !== null) { | ||
@@ -425,2 +503,6 @@ nextEffect = nextEffect.nextEffect; | ||
isCommitting = false; | ||
if (process.env.NODE_ENV !== 'production') { | ||
stopCommitLifeCyclesTimer(); | ||
stopCommitTimer(); | ||
} | ||
if (typeof onCommitRoot === 'function') { | ||
@@ -449,3 +531,7 @@ onCommitRoot(finishedWork.stateNode); | ||
var queue = workInProgress.updateQueue; | ||
if (queue !== null) { | ||
var tag = workInProgress.tag; | ||
if (queue !== null && ( | ||
// TODO: Revisit once updateQueue is typed properly to distinguish between | ||
// update payloads for host components and update queues for composites | ||
tag === ClassComponent || tag === HostRoot)) { | ||
newPriority = getPendingPriority(queue); | ||
@@ -485,2 +571,5 @@ } | ||
if (next !== null) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
stopWorkTimer(workInProgress); | ||
} | ||
if (process.env.NODE_ENV !== 'production' && ReactFiberInstrumentation.debugTool) { | ||
@@ -524,2 +613,5 @@ ReactFiberInstrumentation.debugTool.onCompleteWork(workInProgress); | ||
if (process.env.NODE_ENV !== 'production') { | ||
stopWorkTimer(workInProgress); | ||
} | ||
if (process.env.NODE_ENV !== 'production' && ReactFiberInstrumentation.debugTool) { | ||
@@ -560,2 +652,5 @@ ReactFiberInstrumentation.debugTool.onCompleteWork(workInProgress); | ||
// See if beginning this work spawns more work. | ||
if (process.env.NODE_ENV !== 'production') { | ||
startWorkTimer(workInProgress); | ||
} | ||
var next = beginWork(current, workInProgress, nextPriorityLevel); | ||
@@ -580,3 +675,2 @@ if (process.env.NODE_ENV !== 'production' && ReactFiberInstrumentation.debugTool) { | ||
function performFailedUnitOfWork(workInProgress) { | ||
// The current, flushed, state of this fiber is the alternate. | ||
@@ -589,2 +683,5 @@ // Ideally nothing should rely on this, but relying on it here | ||
// See if beginning this work spawns more work. | ||
if (process.env.NODE_ENV !== 'production') { | ||
startWorkTimer(workInProgress); | ||
} | ||
var next = beginFailedWork(current, workInProgress, nextPriorityLevel); | ||
@@ -642,3 +739,3 @@ if (process.env.NODE_ENV !== 'production' && ReactFiberInstrumentation.debugTool) { | ||
function workLoop(priorityLevel, deadline, deadlineHasExpired) { | ||
function workLoop(priorityLevel, deadline) { | ||
// Clear any errors. | ||
@@ -704,11 +801,12 @@ clearErrors(); | ||
} | ||
return deadlineHasExpired; | ||
} | ||
function performWork(priorityLevel, deadline) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
startWorkLoopTimer(); | ||
} | ||
invariant(!isPerformingWork, 'performWork was called recursively. This error is likely caused ' + 'by a bug in React. Please file an issue.'); | ||
isPerformingWork = true; | ||
var isPerformingDeferredWork = Boolean(deadline); | ||
var deadlineHasExpired = false; | ||
var isPerformingDeferredWork = !!deadline; | ||
@@ -730,7 +828,17 @@ // This outer loop exists so that we can restart the work loop after | ||
// separate function so that it can be optimized by the JS engine. | ||
try { | ||
priorityContextBeforeReconciliation = priorityContext; | ||
priorityContext = nextPriorityLevel; | ||
deadlineHasExpired = workLoop(priorityLevel, deadline, deadlineHasExpired); | ||
} catch (error) { | ||
priorityContextBeforeReconciliation = priorityContext; | ||
var _error3 = null; | ||
if (process.env.NODE_ENV !== 'production') { | ||
_error3 = invokeGuardedCallback(null, workLoop, null, priorityLevel, deadline); | ||
} else { | ||
try { | ||
workLoop(priorityLevel, deadline); | ||
} catch (e) { | ||
_error3 = e; | ||
} | ||
} | ||
// Reset the priority context to its value before reconcilation. | ||
priorityContext = priorityContextBeforeReconciliation; | ||
if (_error3 !== null) { | ||
// We caught an error during either the begin or complete phases. | ||
@@ -740,9 +848,6 @@ var failedWork = nextUnitOfWork; | ||
if (failedWork !== null) { | ||
// Reset the priority context to its value before reconciliation. | ||
priorityContext = priorityContextBeforeReconciliation; | ||
// "Capture" the error by finding the nearest boundary. If there is no | ||
// error boundary, the nearest host container acts as one. If | ||
// captureError returns null, the error was intentionally ignored. | ||
var maybeBoundary = captureError(failedWork, error); | ||
var maybeBoundary = captureError(failedWork, _error3); | ||
if (maybeBoundary !== null) { | ||
@@ -772,6 +877,4 @@ var boundary = maybeBoundary; | ||
// inside resetAfterCommit. | ||
fatalError = error; | ||
fatalError = _error3; | ||
} | ||
} finally { | ||
priorityContext = priorityContextBeforeReconciliation; | ||
} | ||
@@ -819,2 +922,3 @@ | ||
isPerformingWork = false; | ||
deadlineHasExpired = false; | ||
fatalError = null; | ||
@@ -824,2 +928,5 @@ firstUncaughtError = null; | ||
failedBoundaries = null; | ||
if (process.env.NODE_ENV !== 'production') { | ||
stopWorkLoopTimer(); | ||
} | ||
@@ -838,2 +945,3 @@ // It's safe to throw any unhandled errors. | ||
ReactDebugCurrentFiber.current = null; | ||
ReactDebugCurrentFiber.phase = null; | ||
} | ||
@@ -963,3 +1071,3 @@ // It is no longer valid because this unit of work failed. | ||
// to check the alternate. | ||
return Boolean(capturedErrors !== null && (capturedErrors.has(fiber) || fiber.alternate !== null && capturedErrors.has(fiber.alternate))); | ||
return capturedErrors !== null && (capturedErrors.has(fiber) || fiber.alternate !== null && capturedErrors.has(fiber.alternate)); | ||
} | ||
@@ -970,3 +1078,3 @@ | ||
// needing to check the alternate. | ||
return Boolean(failedBoundaries !== null && (failedBoundaries.has(fiber) || fiber.alternate !== null && failedBoundaries.has(fiber.alternate))); | ||
return failedBoundaries !== null && (failedBoundaries.has(fiber) || fiber.alternate !== null && failedBoundaries.has(fiber.alternate)); | ||
} | ||
@@ -1002,5 +1110,10 @@ | ||
var instance = effectfulFiber.stateNode; | ||
var info = { | ||
componentStack: capturedError.componentStack | ||
}; | ||
// Allow the boundary to handle the error, usually by scheduling | ||
// an update to itself | ||
instance.unstable_handleError(error); | ||
instance.unstable_handleError(error, info); | ||
return; | ||
@@ -1037,2 +1150,5 @@ case HostRoot: | ||
} | ||
if (process.env.NODE_ENV !== 'production') { | ||
stopWorkTimer(node); | ||
} | ||
node = node['return']; | ||
@@ -1062,2 +1178,6 @@ } | ||
function scheduleUpdate(fiber, priorityLevel) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
recordScheduleUpdate(); | ||
} | ||
if (priorityLevel <= nextPriorityLevel) { | ||
@@ -1070,2 +1190,9 @@ // We must reset the current unit of work pointer so that we restart the | ||
if (process.env.NODE_ENV !== 'production') { | ||
if (fiber.tag === ClassComponent) { | ||
var instance = fiber.stateNode; | ||
warnAboutInvalidUpdates(instance); | ||
} | ||
} | ||
var node = fiber; | ||
@@ -1072,0 +1199,0 @@ var shouldContinue = true; |
@@ -14,7 +14,6 @@ /** | ||
var _prodInvariant = require('./reactProdInvariant'); | ||
var ReactInstanceMap = require('./ReactInstanceMap'); | ||
var ReactCurrentOwner = require('react/lib/ReactCurrentOwner'); | ||
var getComponentName = require('./getComponentName'); | ||
var invariant = require('fbjs/lib/invariant'); | ||
@@ -78,3 +77,3 @@ | ||
var instance = ownerFiber.stateNode; | ||
process.env.NODE_ENV !== 'production' ? warning(instance._warnedAboutRefsInRender, '%s is accessing isMounted inside its render() function. ' + 'render() should be a pure function of props and state. It should ' + 'never access something that requires stale data from the previous ' + 'render, such as refs. Move this logic to componentDidMount and ' + 'componentDidUpdate instead.', getComponentName(ownerFiber)) : void 0; | ||
process.env.NODE_ENV !== 'production' ? warning(instance._warnedAboutRefsInRender, '%s is accessing isMounted inside its render() function. ' + 'render() should be a pure function of props and state. It should ' + 'never access something that requires stale data from the previous ' + 'render, such as refs. Move this logic to componentDidMount and ' + 'componentDidUpdate instead.', getComponentName(ownerFiber) || 'A component') : void 0; | ||
instance._warnedAboutRefsInRender = true; | ||
@@ -194,3 +193,3 @@ } | ||
invariant(a.alternate === b, 'Return fibers should always be each others\' alternates.'); | ||
invariant(a.alternate === b, "Return fibers should always be each others' alternates."); | ||
} | ||
@@ -241,10 +240,2 @@ // If the root is not a host container, we're in a disconnected tree. I.e. | ||
return null; | ||
}; | ||
function getComponentName(fiber) { | ||
var type = fiber.type; | ||
var instance = fiber.stateNode; | ||
var constructor = instance && instance.constructor; | ||
return type.displayName || constructor && constructor.displayName || type.name || constructor && constructor.name || 'A Component'; | ||
} | ||
exports.getComponentName = getComponentName; | ||
}; |
@@ -14,4 +14,3 @@ /** | ||
var _prodInvariant = require('./reactProdInvariant'), | ||
_assign = require('object-assign'); | ||
var _assign = require('object-assign'); | ||
@@ -66,3 +65,3 @@ var _require = require('./ReactTypeOfSideEffect'), | ||
function ensureUpdateQueue(fiber) { | ||
if (fiber.updateQueue) { | ||
if (fiber.updateQueue !== null) { | ||
// We already have an update queue. | ||
@@ -97,3 +96,3 @@ return fiber.updateQueue; | ||
var currentQueue = current.updateQueue; | ||
if (!currentQueue) { | ||
if (currentQueue === null) { | ||
// The source fiber does not have an update queue. | ||
@@ -104,3 +103,3 @@ workInProgress.updateQueue = null; | ||
// If the alternate already has a queue, reuse the previous object. | ||
var altQueue = workInProgress.updateQueue || {}; | ||
var altQueue = workInProgress.updateQueue !== null ? workInProgress.updateQueue : {}; | ||
altQueue.first = currentQueue.first; | ||
@@ -133,3 +132,3 @@ altQueue.last = currentQueue.last; | ||
function insertUpdateIntoQueue(queue, update, insertAfter, insertBefore) { | ||
if (insertAfter) { | ||
if (insertAfter !== null) { | ||
insertAfter.next = update; | ||
@@ -142,3 +141,3 @@ } else { | ||
if (insertBefore) { | ||
if (insertBefore !== null) { | ||
update.next = insertBefore; | ||
@@ -157,3 +156,3 @@ } else { | ||
var insertBefore = null; | ||
if (queue.last && comparePriority(queue.last.priorityLevel, priorityLevel) <= 0) { | ||
if (queue.last !== null && comparePriority(queue.last.priorityLevel, priorityLevel) <= 0) { | ||
// Fast path for the common case where the update should be inserted at | ||
@@ -164,3 +163,3 @@ // the end of the queue. | ||
insertBefore = queue.first; | ||
while (insertBefore && comparePriority(insertBefore.priorityLevel, priorityLevel) <= 0) { | ||
while (insertBefore !== null && comparePriority(insertBefore.priorityLevel, priorityLevel) <= 0) { | ||
insertAfter = insertBefore; | ||
@@ -204,7 +203,7 @@ insertBefore = insertBefore.next; | ||
var queue1 = ensureUpdateQueue(fiber); | ||
var queue2 = fiber.alternate ? ensureUpdateQueue(fiber.alternate) : null; | ||
var queue2 = fiber.alternate !== null ? ensureUpdateQueue(fiber.alternate) : null; | ||
// Warn if an update is scheduled from inside an updater function. | ||
if (process.env.NODE_ENV !== 'production') { | ||
if (queue1.isProcessing || queue2 && queue2.isProcessing) { | ||
if (queue1.isProcessing || queue2 !== null && queue2.isProcessing) { | ||
process.env.NODE_ENV !== 'production' ? warning(false, 'An update (setState, replaceState, or forceUpdate) was scheduled ' + 'from inside an update function. Update functions should be pure, ' + 'with zero side-effects. Consider using componentDidUpdate or a ' + 'callback.') : void 0; | ||
@@ -216,5 +215,5 @@ } | ||
var insertAfter1 = findInsertionPosition(queue1, update); | ||
var insertBefore1 = insertAfter1 ? insertAfter1.next : queue1.first; | ||
var insertBefore1 = insertAfter1 !== null ? insertAfter1.next : queue1.first; | ||
if (!queue2) { | ||
if (queue2 === null) { | ||
// If there's no alternate queue, there's nothing else to do but insert. | ||
@@ -227,3 +226,3 @@ insertUpdateIntoQueue(queue1, update, insertAfter1, insertBefore1); | ||
var insertAfter2 = findInsertionPosition(queue2, update); | ||
var insertBefore2 = insertAfter2 ? insertAfter2.next : queue2.first; | ||
var insertBefore2 = insertAfter2 !== null ? insertAfter2.next : queue2.first; | ||
@@ -245,6 +244,6 @@ // Now we can insert into the first queue. This must come after finding both | ||
// have changed. | ||
if (!insertAfter2) { | ||
if (insertAfter2 === null) { | ||
queue2.first = update; | ||
} | ||
if (!insertBefore2) { | ||
if (insertBefore2 === null) { | ||
queue2.last = null; | ||
@@ -300,3 +299,3 @@ } | ||
function getPendingPriority(queue) { | ||
return queue.first ? queue.first.priorityLevel : NoWork; | ||
return queue.first !== null ? queue.first.priorityLevel : NoWork; | ||
} | ||
@@ -306,3 +305,3 @@ exports.getPendingPriority = getPendingPriority; | ||
function addTopLevelUpdate(fiber, partialState, callback, priorityLevel) { | ||
var isTopLevelUnmount = Boolean(partialState && partialState.element === null); | ||
var isTopLevelUnmount = partialState.element === null; | ||
@@ -324,9 +323,9 @@ var update = { | ||
var queue1 = fiber.updateQueue; | ||
var queue2 = fiber.alternate && fiber.alternate.updateQueue; | ||
var queue2 = fiber.alternate !== null ? fiber.alternate.updateQueue : null; | ||
if (queue1 && update.next) { | ||
if (queue1 !== null && update.next !== null) { | ||
update.next = null; | ||
queue1.last = update; | ||
} | ||
if (queue2 && update2 && update2.next) { | ||
if (queue2 !== null && update2 !== null && update2.next !== null) { | ||
update2.next = null; | ||
@@ -364,3 +363,3 @@ queue2.last = update; | ||
var update = queue.first; | ||
while (update && comparePriority(update.priorityLevel, priorityLevel) <= 0) { | ||
while (update !== null && comparePriority(update.priorityLevel, priorityLevel) <= 0) { | ||
// Remove each update from the queue right before it is processed. That way | ||
@@ -370,3 +369,3 @@ // if setState is called from inside an updater function, the new update | ||
queue.first = update.next; | ||
if (!queue.first) { | ||
if (queue.first === null) { | ||
queue.last = null; | ||
@@ -405,3 +404,3 @@ } | ||
if (!queue.first && !callbackList && !queue.hasForceUpdate) { | ||
if (queue.first === null && callbackList === null && !queue.hasForceUpdate) { | ||
// The queue is empty and there are no callbacks. We can reset it. | ||
@@ -421,3 +420,3 @@ workInProgress.updateQueue = null; | ||
var callbackList = queue.callbackList; | ||
if (!callbackList) { | ||
if (callbackList === null) { | ||
return; | ||
@@ -427,3 +426,3 @@ } | ||
var _callback = callbackList[i]; | ||
invariant(typeof _callback === 'function', 'Invalid argument passed as callback. Expected a function. Instead ' + 'received: %s', String(_callback)); | ||
invariant(typeof _callback === 'function', 'Invalid argument passed as callback. Expected a function. Instead ' + 'received: %s', _callback); | ||
_callback.call(context); | ||
@@ -430,0 +429,0 @@ } |
@@ -23,3 +23,2 @@ /** | ||
var ReactInstanceMap = { | ||
/** | ||
@@ -45,5 +44,4 @@ * This API should be called `delete` but we'd have to make sure to always | ||
} | ||
}; | ||
module.exports = ReactInstanceMap; |
@@ -249,4 +249,4 @@ /** | ||
// Remove any rendered children. | ||
ReactChildReconciler.unmountChildren(prevChildren, false, /* safely */ | ||
false /* skipLifecycle */ | ||
ReactChildReconciler.unmountChildren(prevChildren, false /* safely */ | ||
, false /* skipLifecycle */ | ||
); | ||
@@ -272,4 +272,4 @@ for (var name in prevChildren) { | ||
// Remove any rendered children. | ||
ReactChildReconciler.unmountChildren(prevChildren, false, /* safely */ | ||
false /* skipLifecycle */ | ||
ReactChildReconciler.unmountChildren(prevChildren, false /* safely */ | ||
, false /* skipLifecycle */ | ||
); | ||
@@ -276,0 +276,0 @@ for (var name in prevChildren) { |
@@ -107,5 +107,4 @@ /** | ||
} | ||
}; | ||
module.exports = ReactOwner; |
@@ -363,3 +363,3 @@ /** | ||
return { | ||
'Component': key, | ||
Component: key, | ||
'Total time (ms)': roundFloat(totalDuration), | ||
@@ -432,4 +432,4 @@ 'Instance count': instanceCount, | ||
'Owner > Node': stat.key, | ||
'Operation': stat.type, | ||
'Payload': typeof stat.payload === 'object' ? JSON.stringify(stat.payload) : stat.payload, | ||
Operation: stat.type, | ||
Payload: typeof stat.payload === 'object' ? JSON.stringify(stat.payload) : stat.payload, | ||
'Flush index': stat.flushIndex, | ||
@@ -436,0 +436,0 @@ 'Owner Component ID': stat.ownerID, |
@@ -27,3 +27,2 @@ /** | ||
var ReactReconciler = { | ||
/** | ||
@@ -40,4 +39,4 @@ * Initializes the component, renders markup, and registers event listeners. | ||
*/ | ||
mountComponent: function (internalInstance, transaction, hostParent, hostContainerInfo, context, parentDebugID // 0 in production and for roots | ||
) { | ||
mountComponent: function (internalInstance, transaction, hostParent, hostContainerInfo, context, parentDebugID) // 0 in production and for roots | ||
{ | ||
if (process.env.NODE_ENV !== 'production') { | ||
@@ -166,5 +165,4 @@ if (internalInstance._debugID !== 0) { | ||
} | ||
}; | ||
module.exports = ReactReconciler; |
@@ -22,4 +22,4 @@ /** | ||
_assign(ReactSimpleEmptyComponent.prototype, { | ||
mountComponent: function (transaction, hostParent, hostContainerInfo, context, parentDebugID // 0 in production and for roots | ||
) { | ||
mountComponent: function (transaction, hostParent, hostContainerInfo, context, parentDebugID) // 0 in production and for roots | ||
{ | ||
return ReactReconciler.mountComponent(this._renderedComponent, transaction, hostParent, hostContainerInfo, context, parentDebugID); | ||
@@ -26,0 +26,0 @@ }, |
@@ -84,3 +84,5 @@ /** | ||
!this._component ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactTestRenderer: .update() can\'t be called after unmount.') : _prodInvariant('139') : void 0; | ||
var nextWrappedElement = React.createElement(TopLevelWrapper, { child: nextElement }); | ||
var nextWrappedElement = React.createElement(TopLevelWrapper, { | ||
child: nextElement | ||
}); | ||
var component = this._component; | ||
@@ -100,4 +102,4 @@ ReactUpdates.batchedUpdates(function () { | ||
transaction.perform(function () { | ||
ReactReconciler.unmountComponent(component, false, /* safely */ | ||
false /* skipLifecycle */ | ||
ReactReconciler.unmountComponent(component, false /* safely */ | ||
, false /* skipLifecycle */ | ||
); | ||
@@ -158,5 +160,6 @@ }); | ||
var ReactTestMount = { | ||
render: function (nextElement, options) { | ||
var nextWrappedElement = React.createElement(TopLevelWrapper, { child: nextElement }); | ||
var nextWrappedElement = React.createElement(TopLevelWrapper, { | ||
child: nextElement | ||
}); | ||
@@ -171,5 +174,4 @@ var instance = instantiateReactComponent(nextWrappedElement, false); | ||
} | ||
}; | ||
module.exports = ReactTestMount; |
@@ -15,7 +15,6 @@ /** | ||
var _assign = require('object-assign'); | ||
var _extends = _assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _prodInvariant = require('./reactProdInvariant'), | ||
_assign = require('object-assign'); | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
@@ -85,2 +84,5 @@ | ||
}, | ||
shouldDeprioritizeSubtree: function (type, props) { | ||
return false; | ||
}, | ||
createTextInstance: function (text, rootContainerInstance, hostContext, internalInstanceHandle) { | ||
@@ -167,3 +169,5 @@ return { | ||
}; | ||
Object.defineProperty(json, '$$typeof', { value: Symbol['for']('react.test.json') }); | ||
Object.defineProperty(json, '$$typeof', { | ||
value: Symbol['for']('react.test.json') | ||
}); | ||
return json; | ||
@@ -170,0 +174,0 @@ default: |
@@ -15,4 +15,3 @@ /** | ||
var _prodInvariant = require('./reactProdInvariant'), | ||
_assign = require('object-assign'); | ||
var _assign = require('object-assign'); | ||
@@ -19,0 +18,0 @@ function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } |
@@ -21,3 +21,3 @@ /** | ||
var warnOnInvalidCallback = function (callback, callerName) { | ||
process.env.NODE_ENV !== 'production' ? warning(callback === null || typeof callback === 'function', '%s(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callerName, String(callback)) : void 0; | ||
process.env.NODE_ENV !== 'production' ? warning(callback === null || typeof callback === 'function', '%s(...): Expected the last optional `callback` argument to be a ' + 'function. Instead received: %s.', callerName, '' + callback) : void 0; | ||
}; | ||
@@ -41,3 +41,3 @@ } | ||
if (process.env.NODE_ENV !== 'production') { | ||
process.env.NODE_ENV !== 'production' ? warning(ReactCurrentOwner.current == null, 'Cannot update during an existing state transition (such as within ' + '`render` or another component\'s constructor). Render methods should ' + 'be a pure function of props and state; constructor side-effects are ' + 'an anti-pattern, but can be moved to `componentWillMount`.') : void 0; | ||
process.env.NODE_ENV !== 'production' ? warning(ReactCurrentOwner.current == null, 'Cannot update during an existing state transition (such as within ' + "`render` or another component's constructor). Render methods should " + 'be a pure function of props and state; constructor side-effects are ' + 'an anti-pattern, but can be moved to `componentWillMount`.') : void 0; | ||
} | ||
@@ -53,3 +53,2 @@ | ||
var ReactUpdateQueue = { | ||
/** | ||
@@ -112,4 +111,4 @@ * Checks whether or not this composite component is mounted. | ||
if (callback) { | ||
callback = callback === undefined ? null : callback; | ||
callback = callback === undefined ? null : callback; | ||
if (callback !== null) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
@@ -153,4 +152,4 @@ warnOnInvalidCallback(callback, callerName); | ||
if (callback) { | ||
callback = callback === undefined ? null : callback; | ||
callback = callback === undefined ? null : callback; | ||
if (callback !== null) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
@@ -196,4 +195,4 @@ warnOnInvalidCallback(callback, callerName); | ||
if (callback) { | ||
callback = callback === undefined ? null : callback; | ||
callback = callback === undefined ? null : callback; | ||
if (callback !== null) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
@@ -218,5 +217,4 @@ warnOnInvalidCallback(callback, callerName); | ||
} | ||
}; | ||
module.exports = ReactUpdateQueue; |
@@ -13,2 +13,2 @@ /** | ||
module.exports = '16.0.0-alpha.3'; | ||
module.exports = '16.0.0-alpha.5'; |
@@ -344,3 +344,2 @@ /** | ||
if (responderInst) { | ||
var terminationRequestEvent = ResponderSyntheticEvent.getPooled(eventTypes.responderTerminationRequest, responderInst, nativeEvent, nativeEventTarget); | ||
@@ -416,3 +415,2 @@ terminationRequestEvent.touchHistory = ResponderTouchHistoryStore.touchHistory; | ||
var ResponderEventPlugin = { | ||
/* For unit testing only */ | ||
@@ -419,0 +417,0 @@ _getResponder: function () { |
@@ -11,2 +11,4 @@ /** | ||
/* eslint valid-typeof: 0 */ | ||
'use strict'; | ||
@@ -106,3 +108,2 @@ | ||
_assign(SyntheticEvent.prototype, { | ||
preventDefault: function () { | ||
@@ -118,3 +119,2 @@ this.defaultPrevented = true; | ||
} else if (typeof event.returnValue !== 'unknown') { | ||
// eslint-disable-line valid-typeof | ||
event.returnValue = false; | ||
@@ -134,3 +134,2 @@ } | ||
} else if (typeof event.cancelBubble !== 'unknown') { | ||
// eslint-disable-line valid-typeof | ||
// The ChangeEventPlugin registers a "propertychange" event for | ||
@@ -184,3 +183,2 @@ // IE. This event does not support bubbling or cancelling, and | ||
} | ||
}); | ||
@@ -201,3 +199,3 @@ | ||
if (prop !== 'isPersistent' && !target.constructor.Interface.hasOwnProperty(prop) && shouldBeReleasedProperties.indexOf(prop) === -1) { | ||
process.env.NODE_ENV !== 'production' ? warning(didWarnForAddedNewProperty || target.isPersistent(), 'This synthetic event is reused for performance reasons. If you\'re ' + 'seeing this, you\'re adding a new property in the synthetic event object. ' + 'The property is never released. See ' + 'https://fb.me/react-event-pooling for more information.') : void 0; | ||
process.env.NODE_ENV !== 'production' ? warning(didWarnForAddedNewProperty || target.isPersistent(), "This synthetic event is reused for performance reasons. If you're " + "seeing this, you're adding a new property in the synthetic event object. " + 'The property is never released. See ' + 'https://fb.me/react-event-pooling for more information.') : void 0; | ||
didWarnForAddedNewProperty = true; | ||
@@ -271,4 +269,4 @@ } | ||
var warningCondition = false; | ||
process.env.NODE_ENV !== 'production' ? warning(warningCondition, 'This synthetic event is reused for performance reasons. If you\'re seeing this, ' + 'you\'re %s `%s` on a released/nullified synthetic event. %s. ' + 'If you must keep the original synthetic event around, use event.persist(). ' + 'See https://fb.me/react-event-pooling for more information.', action, propName, result) : void 0; | ||
process.env.NODE_ENV !== 'production' ? warning(warningCondition, "This synthetic event is reused for performance reasons. If you're seeing this, " + "you're %s `%s` on a released/nullified synthetic event. %s. " + 'If you must keep the original synthetic event around, use event.persist(). ' + 'See https://fb.me/react-event-pooling for more information.', action, propName, result) : void 0; | ||
} | ||
} |
@@ -59,4 +59,3 @@ /** | ||
return TouchHistoryMath.centroidDimension(touchHistory, touchesChangedAfter, true, // isXAxis | ||
true // ofCurrent | ||
); | ||
true); | ||
}, | ||
@@ -66,4 +65,3 @@ | ||
return TouchHistoryMath.centroidDimension(touchHistory, touchesChangedAfter, false, // isXAxis | ||
true // ofCurrent | ||
); | ||
true); | ||
}, | ||
@@ -73,4 +71,3 @@ | ||
return TouchHistoryMath.centroidDimension(touchHistory, touchesChangedAfter, true, // isXAxis | ||
false // ofCurrent | ||
); | ||
false); | ||
}, | ||
@@ -80,4 +77,3 @@ | ||
return TouchHistoryMath.centroidDimension(touchHistory, touchesChangedAfter, false, // isXAxis | ||
false // ofCurrent | ||
); | ||
false); | ||
}, | ||
@@ -88,4 +84,3 @@ | ||
true, // isXAxis | ||
true // ofCurrent | ||
); | ||
true); | ||
}, | ||
@@ -96,4 +91,3 @@ | ||
false, // isXAxis | ||
true // ofCurrent | ||
); | ||
true); | ||
}, | ||
@@ -100,0 +94,0 @@ |
@@ -124,3 +124,3 @@ /** | ||
if (process.env.NODE_ENV !== 'production') { | ||
addendum = ' If you meant to render a collection of children, use an array ' + 'instead or wrap the object using createFragment(object) from the ' + 'React add-ons.'; | ||
addendum = ' If you meant to render a collection of children, use an array ' + 'instead.'; | ||
if (ReactCurrentOwner.current) { | ||
@@ -133,3 +133,3 @@ var name = ReactCurrentOwner.current.getName(); | ||
} | ||
var childrenString = String(children); | ||
var childrenString = '' + children; | ||
!false ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Objects are not valid as a React child (found: %s).%s', childrenString === '[object Object]' ? 'object with keys {' + Object.keys(children).join(', ') + '}' : childrenString, addendum) : _prodInvariant('31', childrenString === '[object Object]' ? 'object with keys {' + Object.keys(children).join(', ') + '}' : childrenString, addendum) : void 0; | ||
@@ -136,0 +136,0 @@ } |
@@ -14,10 +14,8 @@ /** | ||
var _prodInvariant = require('./reactProdInvariant'); | ||
var invariant = require('fbjs/lib/invariant'); | ||
function validateCallback(callback) { | ||
invariant(!callback || typeof callback === 'function', 'Invalid argument passed as callback. Expected a function. Instead ' + 'received: %s', String(callback)); | ||
invariant(!callback || typeof callback === 'function', 'Invalid argument passed as callback. Expected a function. Instead ' + 'received: %s', callback); | ||
} | ||
module.exports = validateCallback; |
{ | ||
"name": "react-test-renderer", | ||
"version": "16.0.0-alpha.3", | ||
"version": "16.0.0-alpha.5", | ||
"description": "React package for snapshot testing.", | ||
@@ -22,3 +22,3 @@ "main": "index.js", | ||
"peerDependencies": { | ||
"react": "^16.0.0-alpha.3" | ||
"react": "^16.0.0-alpha.5" | ||
}, | ||
@@ -25,0 +25,0 @@ "files": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
551329
107
13340
0
327