@samitouri / QOS-React / commits / 5e0ff5f966

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.

Sebastian Markbage committed Jun 7, 2016 at 18:36 UTC 5e0ff5f966fa1bb2bf2d4a46fe6b8c80faf5bc87
5 files changed +41 -14
src/renderers/shared/fiber/ReactFiber.js
+9 -6
@@ -12,14 +12,17 @@
12
13 'use strict';
14
15 -var ReactTypesOfWork = require('ReactTypesOfWork');
15 +import type { TypeOfWork } from 'ReactTypeOfWork';
16 +import type { PriorityLevel } from 'ReactPriorityLevel';
17 +
18 +var ReactTypeOfWork = require('ReactTypeOfWork');
19 var {
20 IndeterminateComponent,
21 ClassComponent,
22 HostComponent,
23 CoroutineComponent,
24 YieldComponent,
22 -} = ReactTypesOfWork;
25 +} = ReactTypeOfWork;
26
27 var ReactElement = require('ReactElement');
28
@@ -32,7 +35,7 @@ import type { ReactCoroutine, ReactYield } from 'ReactCoroutine';
35 type Instance = {
36
37 // Tag identifying the type of fiber.
35 - tag: number,
38 + tag: TypeOfWork,
39
40 // The parent Fiber used to create this one. The type is constrained to the
41 // Instance part of the Fiber since it is not safe to traverse the tree from
@@ -71,7 +74,7 @@ export type Fiber = Instance & {
74 output: any, // This type will be more specific once we overload the tag.
75
76 // This will be used to quickly determine if a subtree has no pending changes.
74 - hasPendingChanges: bool,
77 + pendingWorkPriority: PriorityLevel,
78
79 // This is a pooled version of a Fiber. Every fiber that gets updated will
80 // eventually have a pair. There are cases when we can clean up pairs to save
@@ -80,7 +83,7 @@ export type Fiber = Instance & {
83
84 };
85
83 -var createFiber = function(tag : number, key : null | string) : Fiber {
86 +var createFiber = function(tag : TypeOfWork, key : null | string) : Fiber {
87 return {
88
89 // Instance
@@ -106,7 +109,7 @@ var createFiber = function(tag : number, key : null | string) : Fiber {
109 memoizedInput: null,
110 output: null,
111
109 - hasPendingChanges: true,
112 + pendingWorkPriority: 0,
113
114 alternate: null,
115
src/renderers/shared/fiber/ReactFiberBeginWork.js
+2 -2
@@ -16,7 +16,7 @@ import type { ReactCoroutine } from 'ReactCoroutine';
16 import type { Fiber } from 'ReactFiber';
17
18 var ReactChildFiber = require('ReactChildFiber');
19 -var ReactTypesOfWork = require('ReactTypesOfWork');
19 +var ReactTypeOfWork = require('ReactTypeOfWork');
20 var {
21 IndeterminateComponent,
22 FunctionalComponent,
@@ -25,7 +25,7 @@ var {
25 CoroutineComponent,
26 CoroutineHandlerPhase,
27 YieldComponent,
28 -} = ReactTypesOfWork;
28 +} = ReactTypeOfWork;
29
30 function reconcileChildren(current, workInProgress, nextChildren) {
31 workInProgress.child = ReactChildFiber.reconcileChildFibers(
src/renderers/shared/fiber/ReactFiberCompleteWork.js
+2 -2
@@ -18,7 +18,7 @@ import type { Fiber } from 'ReactFiber';
18 import type { ReifiedYield } from 'ReactReifiedYield';
19
20 var ReactChildFiber = require('ReactChildFiber');
21 -var ReactTypesOfWork = require('ReactTypesOfWork');
21 +var ReactTypeOfWork = require('ReactTypeOfWork');
22 var {
23 IndeterminateComponent,
24 FunctionalComponent,
@@ -27,7 +27,7 @@ var {
27 CoroutineComponent,
28 CoroutineHandlerPhase,
29 YieldComponent,
30 -} = ReactTypesOfWork;
30 +} = ReactTypeOfWork;
31
32 function transferOutput(child : ?Fiber, parent : Fiber) {
33 // If we have a single result, we just pass that through as the output to
src/renderers/shared/fiber/ReactPriorityLevel.js new
+24
@@ -0,0 +1,24 @@
1 +/**
2 + * Copyright 2013-present, Facebook, Inc.
3 + * All rights reserved.
4 + *
5 + * This source code is licensed under the BSD-style license found in the
6 + * LICENSE file in the root directory of this source tree. An additional grant
7 + * of patent rights can be found in the PATENTS file in the same directory.
8 + *
9 + * @providesModule ReactPriorityLevel
10 + * @flow
11 + */
12 +
13 +'use strict';
14 +
15 +export type PriorityLevel = 0 | 1 | 2 | 3 | 4 | 5;
16 +
17 +module.exports = {
18 + NoWork: 0, // No work is pending.
19 + SynchronousPriority: 1, // For controlled text inputs. Synchronous side-effects.
20 + AnimationPriority: 2, // Needs to complete before the next frame.
21 + HighPriority: 3, // Interaction that needs to complete pretty soon to feel responsive.
22 + LowPriority: 4, // Data fetching, or result from updating stores.
23 + OffscreenPriority: 5, // Won't be visible but do the work in case it becomes visible.
24 +};
src/renderers/shared/fiber/ReactTypeOfWork.js renamed
+4 -4
@@ -6,13 +6,15 @@
6 * LICENSE file in the root directory of this source tree. An additional grant
7 * of patent rights can be found in the PATENTS file in the same directory.
8 *
9 - * @providesModule ReactTypesOfWork
9 + * @providesModule ReactTypeOfWork
10 * @flow
11 */
12
13 'use strict';
14
15 -var TypesOfWork = {
15 +export type TypeOfWork = 0 | 1 | 2 | 3 | 4 | 5 | 6;
16 +
17 +module.exports = {
18 IndeterminateComponent: 0, // Before we know whether it is functional or class
19 FunctionalComponent: 1,
20 ClassComponent: 2,
@@ -21,5 +23,3 @@ var TypesOfWork = {
23 CoroutineHandlerPhase: 5,
24 YieldComponent: 6,
25 };
24 -
25 -module.exports = TypesOfWork;