mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Pass props explicitly instead of getting them off currentElement
We don't store currentElement and I'm trying to get rid of accessing the Fiber directly inside the host config.
This commit is contained in:
@@ -453,6 +453,7 @@ var ReactDOMFiberComponent = {
|
||||
|
||||
mountComponent: function(
|
||||
workInProgress : Fiber,
|
||||
props : Object,
|
||||
hostParent : Fiber,
|
||||
hostContainerInfo : Object,
|
||||
context : Object
|
||||
@@ -463,8 +464,6 @@ var ReactDOMFiberComponent = {
|
||||
workInProgress._hostParent = hostParent;
|
||||
workInProgress._hostContainerInfo = hostContainerInfo;
|
||||
|
||||
var props = workInProgress._currentElement.props;
|
||||
|
||||
switch (workInProgress._tag) {
|
||||
case 'audio':
|
||||
case 'form':
|
||||
@@ -577,13 +576,13 @@ var ReactDOMFiberComponent = {
|
||||
|
||||
switch (workInProgress._tag) {
|
||||
case 'input':
|
||||
ReactDOMFiberInput.postMountWrapper(workInProgress);
|
||||
ReactDOMFiberInput.postMountWrapper(workInProgress, props);
|
||||
if (props.autoFocus) {
|
||||
focusNode(getNode(workInProgress));
|
||||
}
|
||||
break;
|
||||
case 'textarea':
|
||||
ReactDOMFiberTextarea.postMountWrapper(workInProgress);
|
||||
ReactDOMFiberTextarea.postMountWrapper(workInProgress, props);
|
||||
if (props.autoFocus) {
|
||||
focusNode(getNode(workInProgress));
|
||||
}
|
||||
@@ -599,7 +598,7 @@ var ReactDOMFiberComponent = {
|
||||
}
|
||||
break;
|
||||
case 'option':
|
||||
ReactDOMFiberOption.postMountWrapper(workInProgress);
|
||||
ReactDOMFiberOption.postMountWrapper(workInProgress, props);
|
||||
break;
|
||||
default:
|
||||
if (typeof props.onClick === 'function') {
|
||||
@@ -652,29 +651,29 @@ var ReactDOMFiberComponent = {
|
||||
// Update the wrapper around inputs *after* updating props. This has to
|
||||
// happen after `updateDOMProperties`. Otherwise HTML5 input validations
|
||||
// raise warnings and prevent the new value from being assigned.
|
||||
ReactDOMFiberInput.updateWrapper(workInProgress);
|
||||
ReactDOMFiberInput.updateWrapper(workInProgress, nextProps);
|
||||
break;
|
||||
case 'textarea':
|
||||
ReactDOMFiberTextarea.updateWrapper(workInProgress);
|
||||
ReactDOMFiberTextarea.updateWrapper(workInProgress, nextProps);
|
||||
break;
|
||||
case 'select':
|
||||
// <select> value update needs to occur after <option> children
|
||||
// reconciliation
|
||||
ReactDOMFiberSelect.postUpdateWrapper(workInProgress);
|
||||
ReactDOMFiberSelect.postUpdateWrapper(workInProgress, nextProps);
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
restoreControlledState: function(finishedWork : Fiber) {
|
||||
restoreControlledState: function(finishedWork : Fiber, props : Object) {
|
||||
switch (finishedWork.type) {
|
||||
case 'input':
|
||||
ReactDOMFiberInput.restoreControlledState(finishedWork);
|
||||
ReactDOMFiberInput.restoreControlledState(finishedWork, props);
|
||||
return;
|
||||
case 'textarea':
|
||||
ReactDOMFiberTextarea.restoreControlledState(finishedWork);
|
||||
ReactDOMFiberTextarea.restoreControlledState(finishedWork, props);
|
||||
return;
|
||||
case 'select':
|
||||
ReactDOMFiberSelect.restoreControlledState(finishedWork);
|
||||
ReactDOMFiberSelect.restoreControlledState(finishedWork, props);
|
||||
return;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -113,7 +113,7 @@ var ReactDOMInput = {
|
||||
'both). Decide between using a controlled or uncontrolled input ' +
|
||||
'element and remove one of these props. More info: ' +
|
||||
'https://fb.me/react-controlled-components',
|
||||
owner && owner.getName() || 'A component',
|
||||
getCurrentOwnerName() || 'A component',
|
||||
props.type
|
||||
);
|
||||
didWarnValueDefaultValue = true;
|
||||
@@ -131,9 +131,7 @@ var ReactDOMInput = {
|
||||
}
|
||||
},
|
||||
|
||||
updateWrapper: function(inst : Fiber) {
|
||||
var props = inst._currentElement.props;
|
||||
|
||||
updateWrapper: function(inst : Fiber, props : Object) {
|
||||
if (__DEV__) {
|
||||
var controlled = isControlled(props);
|
||||
|
||||
@@ -204,9 +202,7 @@ var ReactDOMInput = {
|
||||
}
|
||||
},
|
||||
|
||||
postMountWrapper: function(inst : Fiber) {
|
||||
var props = inst._currentElement.props;
|
||||
|
||||
postMountWrapper: function(inst : Fiber, props : Object) {
|
||||
// This is in postMount because we need access to the DOM node, which is not
|
||||
// available until after the component has mounted.
|
||||
var node = ReactDOMComponentTree.getNodeFromInstance(inst);
|
||||
@@ -254,9 +250,8 @@ var ReactDOMInput = {
|
||||
}
|
||||
},
|
||||
|
||||
restoreControlledState: function(inst : Fiber) {
|
||||
ReactDOMInput.updateWrapper(inst);
|
||||
var props = inst._currentElement.props;
|
||||
restoreControlledState: function(inst : Fiber, props : Object) {
|
||||
ReactDOMInput.updateWrapper(inst, props);
|
||||
updateNamedCousins(inst, props);
|
||||
},
|
||||
};
|
||||
@@ -292,6 +287,7 @@ function updateNamedCousins(thisInstance, props) {
|
||||
// That's probably okay; we don't support it just as we don't support
|
||||
// mixing React radio buttons with non-React ones.
|
||||
var otherInstance = ReactDOMComponentTree.getInstanceFromNode(otherNode);
|
||||
// TODO: Ensure that otherInstance is the current Fiber instead of wip.
|
||||
invariant(
|
||||
otherInstance,
|
||||
'ReactDOMInput: Mixing React and non-React radio inputs with the ' +
|
||||
@@ -300,7 +296,7 @@ function updateNamedCousins(thisInstance, props) {
|
||||
// If this is a controlled radio button group, forcing the input that
|
||||
// was previously checked to update will cause it to be come re-checked
|
||||
// as appropriate.
|
||||
ReactDOMInput.updateWrapper(otherInstance);
|
||||
ReactDOMInput.updateWrapper(otherInstance, otherInstance.memoizedProps);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,9 +99,8 @@ var ReactDOMOption = {
|
||||
inst._wrapperState = {selected: selected};
|
||||
},
|
||||
|
||||
postMountWrapper: function(inst : Fiber) {
|
||||
postMountWrapper: function(inst : Fiber, props : Object) {
|
||||
// value="" should make a value attribute (#6219)
|
||||
var props = inst._currentElement.props;
|
||||
if (props.value != null) {
|
||||
var node = ReactDOMComponentTree.getNodeFromInstance(inst);
|
||||
node.setAttribute('value', props.value);
|
||||
|
||||
@@ -154,9 +154,7 @@ var ReactDOMSelect = {
|
||||
return inst._wrapperState.initialValue;
|
||||
},
|
||||
|
||||
postUpdateWrapper: function(inst : Fiber) {
|
||||
var props = inst._currentElement.props;
|
||||
|
||||
postUpdateWrapper: function(inst : Fiber, props : Object) {
|
||||
// After the initial mount, we control selected-ness manually so don't pass
|
||||
// this value down
|
||||
inst._wrapperState.initialValue = undefined;
|
||||
@@ -178,8 +176,7 @@ var ReactDOMSelect = {
|
||||
}
|
||||
},
|
||||
|
||||
restoreControlledState: function(inst : Fiber) {
|
||||
var props = inst._currentElement.props;
|
||||
restoreControlledState: function(inst : Fiber, props : Object) {
|
||||
var value = props.value;
|
||||
|
||||
if (value != null) {
|
||||
|
||||
@@ -125,9 +125,7 @@ var ReactDOMTextarea = {
|
||||
};
|
||||
},
|
||||
|
||||
updateWrapper: function(inst : Fiber) {
|
||||
var props = inst._currentElement.props;
|
||||
|
||||
updateWrapper: function(inst : Fiber, props : Object) {
|
||||
var node = ReactDOMComponentTree.getNodeFromInstance(inst);
|
||||
var value = props.value;
|
||||
if (value != null) {
|
||||
@@ -148,7 +146,7 @@ var ReactDOMTextarea = {
|
||||
}
|
||||
},
|
||||
|
||||
postMountWrapper: function(inst : Fiber) {
|
||||
postMountWrapper: function(inst : Fiber, props : Object) {
|
||||
// This is in postMount because we need access to the DOM node, which is not
|
||||
// available until after the component has mounted.
|
||||
var node = ReactDOMComponentTree.getNodeFromInstance(inst);
|
||||
@@ -163,9 +161,9 @@ var ReactDOMTextarea = {
|
||||
}
|
||||
},
|
||||
|
||||
restoreControlledState: function(inst : Fiber) {
|
||||
restoreControlledState: function(inst : Fiber, props : Object) {
|
||||
// DOM component is still mounted; update
|
||||
ReactDOMTextarea.updateWrapper(inst);
|
||||
ReactDOMTextarea.updateWrapper(inst, props);
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user