-
Notifications
You must be signed in to change notification settings - Fork 49.8k
[Fiber] Initial implementation of context #8272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
12bee76
a05d1ab
b8cca37
e6a0de5
4ba0eb9
c22b7a0
f9e1bc9
56e1c12
eedca6f
299009c
a6ee5b8
fd8c803
1e42c18
2397f1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,15 @@ var { | |
| reconcileChildFibersInPlace, | ||
| cloneChildFibers, | ||
| } = require('ReactChildFiber'); | ||
|
|
||
| var ReactTypeOfWork = require('ReactTypeOfWork'); | ||
| var { | ||
| getMaskedContext, | ||
| isContextProvider, | ||
| hasContextChanged, | ||
| pushContextProvider, | ||
| resetContext, | ||
| } = require('ReactFiberContext'); | ||
| var { | ||
| IndeterminateComponent, | ||
| FunctionalComponent, | ||
|
|
@@ -144,6 +152,7 @@ module.exports = function<T, P, I, TI, C>( | |
| function updateFunctionalComponent(current, workInProgress) { | ||
| var fn = workInProgress.type; | ||
| var props = workInProgress.pendingProps; | ||
| var context = getMaskedContext(workInProgress); | ||
|
|
||
| // TODO: Disable this before release, since it is not part of the public API | ||
| // I use this for testing to compare the relative overhead of classes. | ||
|
|
@@ -159,9 +168,9 @@ module.exports = function<T, P, I, TI, C>( | |
|
|
||
| if (__DEV__) { | ||
| ReactCurrentOwner.current = workInProgress; | ||
| nextChildren = fn(props); | ||
| nextChildren = fn(props, context); | ||
| } else { | ||
| nextChildren = fn(props); | ||
| nextChildren = fn(props, context); | ||
| } | ||
| reconcileChildren(current, workInProgress, nextChildren); | ||
| return workInProgress.child; | ||
|
|
@@ -190,6 +199,10 @@ module.exports = function<T, P, I, TI, C>( | |
| ReactCurrentOwner.current = workInProgress; | ||
| const nextChildren = instance.render(); | ||
| reconcileChildren(current, workInProgress, nextChildren); | ||
| // Put context on the stack because we will work on children | ||
| if (isContextProvider(workInProgress)) { | ||
| pushContextProvider(workInProgress, true); | ||
| } | ||
| return workInProgress.child; | ||
| } | ||
|
|
||
|
|
@@ -249,13 +262,15 @@ module.exports = function<T, P, I, TI, C>( | |
| } | ||
| var fn = workInProgress.type; | ||
| var props = workInProgress.pendingProps; | ||
| var context = getMaskedContext(workInProgress); | ||
|
|
||
| var value; | ||
|
|
||
| if (__DEV__) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what the reason of such style? or
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think there's any reason for this, putting just current owner assignment in a condition would be equivalent. |
||
| ReactCurrentOwner.current = workInProgress; | ||
| value = fn(props); | ||
| value = fn(props, context); | ||
| } else { | ||
| value = fn(props); | ||
| value = fn(props, context); | ||
| } | ||
|
|
||
| if (typeof value === 'object' && value && typeof value.render === 'function') { | ||
|
|
@@ -345,6 +360,10 @@ module.exports = function<T, P, I, TI, C>( | |
|
|
||
| cloneChildFibers(current, workInProgress); | ||
| markChildAsProgressed(current, workInProgress, priorityLevel); | ||
| // Put context on the stack because we will work on children | ||
| if (isContextProvider(workInProgress)) { | ||
| pushContextProvider(workInProgress, false); | ||
| } | ||
| return workInProgress.child; | ||
| } | ||
|
|
||
|
|
@@ -355,6 +374,11 @@ module.exports = function<T, P, I, TI, C>( | |
| } | ||
|
|
||
| function beginWork(current : ?Fiber, workInProgress : Fiber, priorityLevel : PriorityLevel) : ?Fiber { | ||
| if (!workInProgress.return) { | ||
| // Don't start new work with context on the stack. | ||
| resetContext(); | ||
| } | ||
|
|
||
| if (workInProgress.pendingWorkPriority === NoWork || | ||
| workInProgress.pendingWorkPriority > priorityLevel) { | ||
| return bailoutOnLowPriority(current, workInProgress); | ||
|
|
@@ -375,7 +399,8 @@ module.exports = function<T, P, I, TI, C>( | |
| workInProgress.memoizedProps !== null && | ||
| workInProgress.pendingProps === workInProgress.memoizedProps | ||
| )) && | ||
| workInProgress.updateQueue === null) { | ||
| workInProgress.updateQueue === null && | ||
| !hasContextChanged()) { | ||
| return bailoutOnAlreadyFinishedWork(current, workInProgress); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a new PR I extracted from "should filter context properly in callbacks". It covers the
componentDidUpdatewithnextContextwhich we punted on.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙄 I meant test, not PR