Add Priority Levels Enum

This flag on fibers will be used to track what priority of work is
needed by that subtree, if any at all.

Also fix up the TypeOfWork to have consistent naming and typing.
This commit is contained in:
Sebastian Markbage
2016-06-30 12:55:53 -07:00
parent ed215634be
commit 5e0ff5f966
5 changed files with 41 additions and 14 deletions
+9 -6
View File
@@ -12,14 +12,17 @@
'use strict';
var ReactTypesOfWork = require('ReactTypesOfWork');
import type { TypeOfWork } from 'ReactTypeOfWork';
import type { PriorityLevel } from 'ReactPriorityLevel';
var ReactTypeOfWork = require('ReactTypeOfWork');
var {
IndeterminateComponent,
ClassComponent,
HostComponent,
CoroutineComponent,
YieldComponent,
} = ReactTypesOfWork;
} = ReactTypeOfWork;
var ReactElement = require('ReactElement');
@@ -32,7 +35,7 @@ import type { ReactCoroutine, ReactYield } from 'ReactCoroutine';
type Instance = {
// Tag identifying the type of fiber.
tag: number,
tag: TypeOfWork,
// The parent Fiber used to create this one. The type is constrained to the
// Instance part of the Fiber since it is not safe to traverse the tree from
@@ -71,7 +74,7 @@ export type Fiber = Instance & {
output: any, // This type will be more specific once we overload the tag.
// This will be used to quickly determine if a subtree has no pending changes.
hasPendingChanges: bool,
pendingWorkPriority: PriorityLevel,
// This is a pooled version of a Fiber. Every fiber that gets updated will
// eventually have a pair. There are cases when we can clean up pairs to save
@@ -80,7 +83,7 @@ export type Fiber = Instance & {
};
var createFiber = function(tag : number, key : null | string) : Fiber {
var createFiber = function(tag : TypeOfWork, key : null | string) : Fiber {
return {
// Instance
@@ -106,7 +109,7 @@ var createFiber = function(tag : number, key : null | string) : Fiber {
memoizedInput: null,
output: null,
hasPendingChanges: true,
pendingWorkPriority: 0,
alternate: null,
@@ -16,7 +16,7 @@ import type { ReactCoroutine } from 'ReactCoroutine';
import type { Fiber } from 'ReactFiber';
var ReactChildFiber = require('ReactChildFiber');
var ReactTypesOfWork = require('ReactTypesOfWork');
var ReactTypeOfWork = require('ReactTypeOfWork');
var {
IndeterminateComponent,
FunctionalComponent,
@@ -25,7 +25,7 @@ var {
CoroutineComponent,
CoroutineHandlerPhase,
YieldComponent,
} = ReactTypesOfWork;
} = ReactTypeOfWork;
function reconcileChildren(current, workInProgress, nextChildren) {
workInProgress.child = ReactChildFiber.reconcileChildFibers(
@@ -18,7 +18,7 @@ import type { Fiber } from 'ReactFiber';
import type { ReifiedYield } from 'ReactReifiedYield';
var ReactChildFiber = require('ReactChildFiber');
var ReactTypesOfWork = require('ReactTypesOfWork');
var ReactTypeOfWork = require('ReactTypeOfWork');
var {
IndeterminateComponent,
FunctionalComponent,
@@ -27,7 +27,7 @@ var {
CoroutineComponent,
CoroutineHandlerPhase,
YieldComponent,
} = ReactTypesOfWork;
} = ReactTypeOfWork;
function transferOutput(child : ?Fiber, parent : Fiber) {
// If we have a single result, we just pass that through as the output to
@@ -0,0 +1,24 @@
/**
* 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 ReactPriorityLevel
* @flow
*/
'use strict';
export type PriorityLevel = 0 | 1 | 2 | 3 | 4 | 5;
module.exports = {
NoWork: 0, // No work is pending.
SynchronousPriority: 1, // For controlled text inputs. Synchronous side-effects.
AnimationPriority: 2, // Needs to complete before the next frame.
HighPriority: 3, // Interaction that needs to complete pretty soon to feel responsive.
LowPriority: 4, // Data fetching, or result from updating stores.
OffscreenPriority: 5, // Won't be visible but do the work in case it becomes visible.
};
@@ -6,13 +6,15 @@
* 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 ReactTypesOfWork
* @providesModule ReactTypeOfWork
* @flow
*/
'use strict';
var TypesOfWork = {
export type TypeOfWork = 0 | 1 | 2 | 3 | 4 | 5 | 6;
module.exports = {
IndeterminateComponent: 0, // Before we know whether it is functional or class
FunctionalComponent: 1,
ClassComponent: 2,
@@ -21,5 +23,3 @@ var TypesOfWork = {
CoroutineHandlerPhase: 5,
YieldComponent: 6,
};
module.exports = TypesOfWork;