forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2636155
commit 7c8a090
Showing
8 changed files
with
301 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* Copyright 2013-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @providesModule ReactChildFiber | ||
* @flow | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import type { Fiber } from 'ReactFiber'; | ||
|
||
var ReactElement = require('ReactElement'); | ||
|
||
var ReactFiber = require('ReactFiber'); | ||
|
||
type ReactNode = ReactElement | ReactFragment | ReactText; | ||
|
||
type ReactFragment = Iterable<ReactNode | ReactEmpty>; | ||
|
||
type ReactNodeList = ReactNode | ReactEmpty; | ||
|
||
type ReactText = string | number; | ||
|
||
type ReactEmpty = null | void | boolean; | ||
|
||
function createSubsequentChild(parent : Fiber, previousSibling : Fiber, newChildren) : Fiber { | ||
if (typeof newChildren !== 'object' || newChildren === null) { | ||
return previousSibling; | ||
} | ||
|
||
if (ReactElement.isValidElement(newChildren)) { | ||
var element = (newChildren : ReactElement); | ||
var child = ReactFiber.createFiberFromElement(element); | ||
previousSibling.sibling = child; | ||
child.parent = parent; | ||
return child; | ||
} | ||
|
||
if (Array.isArray(newChildren)) { | ||
let prev : Fiber = previousSibling; | ||
for (var i = 0; i < newChildren.length; i++) { | ||
prev = createSubsequentChild(parent, prev, newChildren[i]); | ||
} | ||
return prev; | ||
} else { | ||
return previousSibling; | ||
} | ||
} | ||
|
||
function createFirstChild(parent, newChildren) { | ||
if (typeof newChildren !== 'object' || newChildren === null) { | ||
parent.child = null; | ||
return null; | ||
} | ||
|
||
if (ReactElement.isValidElement(newChildren)) { | ||
var element = (newChildren : ReactElement); | ||
var child = ReactFiber.createFiberFromElement(element); | ||
parent.child = child; | ||
child.parent = parent; | ||
return child; | ||
} | ||
|
||
if (Array.isArray(newChildren)) { | ||
var prev : ?Fiber = null; | ||
for (var i = 0; i < newChildren.length; i++) { | ||
if (prev == null) { | ||
prev = createFirstChild(parent, newChildren[i]); | ||
} else { | ||
prev = createSubsequentChild(parent, prev, newChildren[i]); | ||
} | ||
} | ||
} else { | ||
parent.child = null; | ||
return null; | ||
} | ||
} | ||
|
||
exports.reconcileChildFibers = function(parent : Fiber, newChildren : ReactNodeList) : void { | ||
createFirstChild(parent, newChildren); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/** | ||
* Copyright 2013-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @providesModule ReactFiberBeginWork | ||
* @flow | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import type { Fiber } from 'ReactFiber'; | ||
|
||
var ReactChildFiber = require('ReactChildFiber'); | ||
var ReactTypesOfWork = require('ReactTypesOfWork'); | ||
var { | ||
IndeterminateComponent, | ||
FunctionalComponent, | ||
ClassComponent, | ||
HostComponent, | ||
} = ReactTypesOfWork; | ||
|
||
function getElement(unitOfWork) : ReactElement { | ||
var element = unitOfWork.input; | ||
if (!element) { | ||
throw new Error('Should be resolved by now'); | ||
} | ||
return (element : ReactElement); | ||
} | ||
|
||
function updateFunctionalComponent(unitOfWork) { | ||
var element = getElement(unitOfWork); | ||
var fn = element.type; | ||
var props = element.props; | ||
console.log('perform work on:', fn.name); | ||
var nextChildren = fn(props); | ||
|
||
ReactChildFiber.reconcileChildFibers( | ||
unitOfWork, | ||
nextChildren | ||
); | ||
} | ||
|
||
function updateHostComponent(unitOfWork) { | ||
var element = getElement(unitOfWork); | ||
console.log('host component', element.type); | ||
|
||
var nextChildren = element.props.children; | ||
ReactChildFiber.reconcileChildFibers( | ||
unitOfWork, | ||
nextChildren | ||
); | ||
} | ||
|
||
function mountIndeterminateComponent(unitOfWork) { | ||
var element = getElement(unitOfWork); | ||
var fn = element.type; | ||
var props = element.props; | ||
var value = fn(props); | ||
if (typeof value === 'object' && value && typeof value.render === 'function') { | ||
console.log('performed work on class:', fn.name); | ||
// Proceed under the assumption that this is a class instance | ||
unitOfWork.tag = ClassComponent; | ||
} else { | ||
console.log('performed work on fn:', fn.name); | ||
// Proceed under the assumption that this is a functional component | ||
unitOfWork.tag = FunctionalComponent; | ||
} | ||
ReactChildFiber.reconcileChildFibers( | ||
unitOfWork, | ||
value | ||
); | ||
} | ||
|
||
exports.beginWork = function(unitOfWork : Fiber) : ?Fiber { | ||
switch (unitOfWork.tag) { | ||
case IndeterminateComponent: | ||
mountIndeterminateComponent(unitOfWork); | ||
break; | ||
case FunctionalComponent: | ||
updateFunctionalComponent(unitOfWork); | ||
break; | ||
case ClassComponent: | ||
// $FlowFixMe | ||
console.log('class component', unitOfWork.input.type.name); | ||
break; | ||
case HostComponent: | ||
updateHostComponent(unitOfWork); | ||
break; | ||
default: | ||
throw new Error('Unknown unit of work tag'); | ||
} | ||
return unitOfWork.child; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Copyright 2013-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @providesModule ReactFiberCompleteWork | ||
* @flow | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import type { Fiber } from 'ReactFiber'; | ||
|
||
var ReactChildFiber = require('ReactChildFiber'); | ||
var ReactTypesOfWork = require('ReactTypesOfWork'); | ||
var { | ||
IndeterminateComponent, | ||
FunctionalComponent, | ||
ClassComponent, | ||
HostComponent, | ||
} = ReactTypesOfWork; | ||
|
||
exports.completeWork = function(unitOfWork : Fiber) : ?Fiber { | ||
switch (unitOfWork.tag) { | ||
case FunctionalComponent: | ||
// $FlowFixMe | ||
console.log('/functional component', unitOfWork.input.type.name); | ||
break; | ||
case ClassComponent: | ||
// $FlowFixMe | ||
console.log('/class component', unitOfWork.input.type.name); | ||
break; | ||
case HostComponent: | ||
// $FlowFixMe | ||
console.log('/host component', unitOfWork.input.type); | ||
break; | ||
case IndeterminateComponent: | ||
throw new Error('An indeterminate component should have become determinate before completing.'); | ||
default: | ||
throw new Error('Unknown unit of work tag'); | ||
} | ||
return null; | ||
}; |
45 changes: 0 additions & 45 deletions
45
src/renderers/shared/fiber/ReactFiberFunctionalComponent.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.