Skip to content

Commit

Permalink
Replace pendingWorkPriority with expiration times
Browse files Browse the repository at this point in the history
Instead of a priority, a fiber has an expiration time that represents
a point in the future by which it should render.

Pending updates still have priorities so that they can be coalesced.

We use a host config method to read the current time. This commit
implements everything except that method, which currently returns a
constant value. So this just proves that expiration times work the same
as priorities when time is frozen. Subsequent commits will show the
effect of advancing time.
  • Loading branch information
acdlite committed Aug 10, 2017
1 parent 7ef34ab commit 796db96
Show file tree
Hide file tree
Showing 11 changed files with 567 additions and 395 deletions.
33 changes: 18 additions & 15 deletions src/renderers/dom/fiber/ReactDOMFiberEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,20 @@ function shouldAutoFocusHostComponent(type: string, props: Props): boolean {
}

// TODO: Better polyfill
let now;
if (
typeof window !== 'undefined' &&
window.performance &&
typeof window.performance.now === 'function'
) {
now = function() {
return performance.now();
};
} else {
now = function() {
return Date.now();
};
}
// let now;
// if (
// typeof window !== 'undefined' &&
// window.performance &&
// typeof window.performance.now === 'function'
// ) {
// now = function() {
// return performance.now();
// };
// } else {
// now = function() {
// return Date.now();
// };
// }

var DOMRenderer = ReactFiberReconciler({
getRootHostContext(rootContainerInstance: Container): HostContext {
Expand Down Expand Up @@ -447,7 +447,10 @@ var DOMRenderer = ReactFiberReconciler({
}
},

now: now,
now() {
// TODO: Use performance.now to enable expiration
return 0;
},

canHydrateInstance(
instance: Instance | TextInstance,
Expand Down
6 changes: 3 additions & 3 deletions src/renderers/noop/ReactNoopEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,15 +412,15 @@ var ReactNoop = {
' '.repeat(depth + 1) + '~',
firstUpdate && firstUpdate.partialState,
firstUpdate.callback ? 'with callback' : '',
'[' + firstUpdate.priorityLevel + ']',
'[' + firstUpdate.expirationTime + ']',
);
var next;
while ((next = firstUpdate.next)) {
log(
' '.repeat(depth + 1) + '~',
next.partialState,
next.callback ? 'with callback' : '',
'[' + firstUpdate.priorityLevel + ']',
'[' + firstUpdate.expirationTime + ']',
);
}
}
Expand All @@ -430,7 +430,7 @@ var ReactNoop = {
' '.repeat(depth) +
'- ' +
(fiber.type ? fiber.type.name || fiber.type : '[root]'),
'[' + fiber.pendingWorkPriority + (fiber.pendingProps ? '*' : '') + ']',
'[' + fiber.expirationTime + (fiber.pendingProps ? '*' : '') + ']',
);
if (fiber.updateQueue) {
logUpdateQueue(fiber.updateQueue, depth);
Expand Down
Loading

0 comments on commit 796db96

Please sign in to comment.