Skip to content

Commit

Permalink
Pass type to the relevant host config methods
Browse files Browse the repository at this point in the history
Instead of reading it from the DOM node.
  • Loading branch information
sebmarkbage committed Dec 13, 2016
1 parent db489a4 commit 6c1592f
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/renderers/art/ReactARTFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ const ARTRenderer = ReactFiberReconciler({
// Noop
},

commitUpdate(instance, oldProps, newProps) {
commitUpdate(instance, type, oldProps, newProps) {
instance._applyProps(instance, newProps, oldProps);
},

Expand Down Expand Up @@ -467,7 +467,7 @@ const ARTRenderer = ReactFiberReconciler({
// Noop
},

prepareUpdate(domElement, oldProps, newProps) {
prepareUpdate(domElement, type, oldProps, newProps) {
return true;
},

Expand Down
19 changes: 5 additions & 14 deletions src/renderers/dom/fiber/ReactDOMFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,16 @@ var DOMRenderer = ReactFiberReconciler({

finalizeInitialChildren(
domElement : Instance,
type : string,
props : Props,
rootContainerInstance : Container,
) : void {
// TODO: we normalize here because DOM renderer expects tag to be lowercase.
// We can change DOM renderer to compare special case against upper case,
// and use tagName (which is upper case for HTML DOM elements). Or we could
// let the renderer "normalize" the fiber type so we don't have to read
// the type from DOM. However we need to remember SVG is case-sensitive.
var tag = domElement.tagName.toLowerCase();
setInitialProperties(domElement, tag, props, rootContainerInstance);
setInitialProperties(domElement, type, props, rootContainerInstance);
},

prepareUpdate(
domElement : Instance,
type : string,
oldProps : Props,
newProps : Props
) : boolean {
Expand All @@ -119,21 +115,16 @@ var DOMRenderer = ReactFiberReconciler({

commitUpdate(
domElement : Instance,
type : string,
oldProps : Props,
newProps : Props,
rootContainerInstance : Container,
internalInstanceHandle : Object,
) : void {
// TODO: we normalize here because DOM renderer expects tag to be lowercase.
// We can change DOM renderer to compare special case against upper case,
// and use tagName (which is upper case for HTML DOM elements). Or we could
// let the renderer "normalize" the fiber type so we don't have to read
// the type from DOM. However we need to remember SVG is case-sensitive.
var tag = domElement.tagName.toLowerCase();
// Update the internal instance handle so that we know which props are
// the current ones.
precacheFiberNode(internalInstanceHandle, domElement);
updateProperties(domElement, tag, oldProps, newProps, rootContainerInstance);
updateProperties(domElement, type, oldProps, newProps, rootContainerInstance);
},

shouldSetTextContent(props : Props) : boolean {
Expand Down
6 changes: 3 additions & 3 deletions src/renderers/noop/ReactNoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ var NoopRenderer = ReactFiberReconciler({
parentInstance.children.push(child);
},

finalizeInitialChildren(domElement : Instance, props : Props) : void {
finalizeInitialChildren(domElement : Instance, type : string, props : Props) : void {
// Noop
},

prepareUpdate(instance : Instance, oldProps : Props, newProps : Props) : boolean {
prepareUpdate(instance : Instance, type : string, oldProps : Props, newProps : Props) : boolean {
return true;
},

commitUpdate(instance : Instance, oldProps : Props, newProps : Props) : void {
commitUpdate(instance : Instance, type : string, oldProps : Props, newProps : Props) : void {
instance.prop = newProps.prop;
},

Expand Down
3 changes: 2 additions & 1 deletion src/renderers/shared/fiber/ReactFiberCommitWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ module.exports = function<T, P, I, TI, C, CX>(
const newProps = finishedWork.memoizedProps;
const oldProps = current.memoizedProps;
const rootContainerInstance = getRootHostContainer();
commitUpdate(instance, oldProps, newProps, rootContainerInstance, finishedWork);
const type = finishedWork.type;
commitUpdate(instance, type, oldProps, newProps, rootContainerInstance, finishedWork);
}
detachRefIfNeeded(current, finishedWork);
return;
Expand Down
7 changes: 4 additions & 3 deletions src/renderers/shared/fiber/ReactFiberCompleteWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ module.exports = function<T, P, I, TI, C, CX>(
}
case HostComponent:
popHostContext(workInProgress);
const type = workInProgress.type;
let newProps = workInProgress.pendingProps;
if (current && workInProgress.stateNode != null) {
// If we have an alternate, that means this is an update and we need to
Expand All @@ -228,7 +229,7 @@ module.exports = function<T, P, I, TI, C, CX>(
newProps = workInProgress.memoizedProps || oldProps;
}
const instance : I = workInProgress.stateNode;
if (prepareUpdate(instance, oldProps, newProps)) {
if (prepareUpdate(instance, type, oldProps, newProps)) {
// This returns true if there was something to update.
markUpdate(workInProgress);
}
Expand All @@ -249,14 +250,14 @@ module.exports = function<T, P, I, TI, C, CX>(
// or completeWork depending on we want to add then top->down or
// bottom->up. Top->down is faster in IE11.
const instance = createInstance(
workInProgress.type,
type,
newProps,
rootContainerInstance,
currentHostContext,
workInProgress
);
appendAllChildren(instance, workInProgress);
finalizeInitialChildren(instance, newProps, rootContainerInstance);
finalizeInitialChildren(instance, type, newProps, rootContainerInstance);

workInProgress.stateNode = instance;
if (workInProgress.ref) {
Expand Down
6 changes: 3 additions & 3 deletions src/renderers/shared/fiber/ReactFiberReconciler.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ export type HostConfig<T, P, I, TI, C, CX> = {

createInstance(type : T, props : P, rootContainerInstance : C, hostContext : CX | null, internalInstanceHandle : OpaqueNode) : I,
appendInitialChild(parentInstance : I, child : I | TI) : void,
finalizeInitialChildren(parentInstance : I, props : P, rootContainerInstance : C) : void,
finalizeInitialChildren(parentInstance : I, type : T, props : P, rootContainerInstance : C) : void,

prepareUpdate(instance : I, oldProps : P, newProps : P) : boolean,
commitUpdate(instance : I, oldProps : P, newProps : P, rootContainerInstance : C, internalInstanceHandle : OpaqueNode) : void,
prepareUpdate(instance : I, type : T, oldProps : P, newProps : P) : boolean,
commitUpdate(instance : I, type : T, oldProps : P, newProps : P, rootContainerInstance : C, internalInstanceHandle : OpaqueNode) : void,

shouldSetTextContent(props : P) : boolean,
resetTextContent(instance : I) : void,
Expand Down

0 comments on commit 6c1592f

Please sign in to comment.