@samitouri / QOS-React / commits / a0902fc306

Generic type added to StackCursor. Default emptyObject replaced with null.

Brian Vaughn committed Dec 21, 2016 at 09:06 UTC a0902fc30675808193f23b22452c5bfc0cd704e7
3 files changed +26 -24
src/renderers/shared/fiber/ReactFiberContext.js
+4 -3
@@ -36,11 +36,11 @@ if (__DEV__) {
36 var checkReactTypeSpec = require('checkReactTypeSpec');
37 }
38
39 -let contextStackCursor : StackCursor = createCursor();
40 -let didPerformWorkStackCursor : StackCursor = createCursor();
39 +let contextStackCursor : StackCursor<?Object> = createCursor((null: ?Object));
40 +let didPerformWorkStackCursor : StackCursor<?boolean> = createCursor((null: ?boolean));
41
42 function getUnmaskedContext() {
43 - return contextStackCursor.current;
43 + return contextStackCursor.current || emptyObject;
44 }
45
46 exports.getMaskedContext = function(workInProgress : Fiber) {
@@ -52,6 +52,7 @@ exports.getMaskedContext = function(workInProgress : Fiber) {
52
53 const unmaskedContext = getUnmaskedContext();
54 const context = {};
55 +
56 for (let key in contextTypes) {
57 context[key] = unmaskedContext[key];
58 }
src/renderers/shared/fiber/ReactFiberHostContext.js
+5 -3
@@ -16,6 +16,8 @@ import type { Fiber } from 'ReactFiber';
16 import type { HostConfig } from 'ReactFiberReconciler';
17 import type { StackCursor } from 'ReactFiberStack';
18
19 +const emptyObject = require('emptyObject');
20 +
21 const {
22 createCursor,
23 pop,
@@ -41,8 +43,8 @@ module.exports = function<T, P, I, TI, C, CX>(
43 getRootHostContext,
44 } = config;
45
44 - let contextStackCursor : StackCursor = createCursor();
45 - let rootInstanceStackCursor : StackCursor = createCursor();
46 + let contextStackCursor : StackCursor<?CX> = createCursor((null: ?CX));
47 + let rootInstanceStackCursor : StackCursor<?C> = createCursor((null: ?C));
48
49 function getRootHostContainer() : C {
50 if (rootInstanceStackCursor.current == null) {
@@ -81,7 +83,7 @@ module.exports = function<T, P, I, TI, C, CX>(
83 throw new Error('Expected root host context to exist.');
84 }
85
84 - const context = contextStackCursor.current;
86 + const context = contextStackCursor.current || emptyObject;
87 const rootInstance = rootInstanceStackCursor.current;
88 const nextContext = getChildHostContext(context, fiber.type, rootInstance);
89
src/renderers/shared/fiber/ReactFiberStack.js
+17 -18
@@ -14,14 +14,13 @@
14
15 import type { Fiber } from 'ReactFiber';
16
17 -export type StackCursor = {|
18 - current: any
17 +export type StackCursor<T> = {|
18 + current: T
19 |};
20
21 -const emptyObject = require('emptyObject');
21 const warning = require('warning');
22
24 -const valueStack : Array<Object> = [];
23 +const valueStack : Array<any> = [];
24
25 if (__DEV__) {
26 var fiberStack : Array<Fiber | null> = [];
@@ -29,9 +28,9 @@ if (__DEV__) {
28
29 let index = -1;
30
32 -exports.createCursor = function() : StackCursor {
31 +exports.createCursor = function<T>(defaultValue : T) : StackCursor<T> {
32 return {
34 - current: null,
33 + current: defaultValue,
34 };
35 };
36
@@ -39,8 +38,8 @@ exports.isEmpty = function() : boolean {
38 return index === -1;
39 };
40
42 -exports.pop = function(
43 - cursor : StackCursor,
41 +exports.pop = function<T>(
42 + cursor : StackCursor<T>,
43 fiber: Fiber | null, // TODO (bvaughn) Tighten up this type to only accept Fiber
44 ) : void {
45 if (index < 0) {
@@ -56,21 +55,21 @@ exports.pop = function(
55 }
56 }
57
59 - valueStack[index] = emptyObject;
58 + valueStack[index] = null;
59
60 if (__DEV__) {
62 - fiberStack[index] = emptyObject;
61 + fiberStack[index] = null;
62 }
63
64 index--;
65
66 cursor.current = index > -1
67 ? valueStack[index]
69 - : null;
68 + : (null : any);
69 };
70
72 -exports.push = function(
73 - cursor : StackCursor,
71 +exports.push = function<T>(
72 + cursor : StackCursor<T>,
73 value : any,
74 fiber: Fiber | null, // TODO (bvaughn) Tighten up this type to only accept Fiber
75 ) : void {
@@ -85,18 +84,18 @@ exports.push = function(
84 }
85 };
86
88 -exports.reset = function(
89 - cursor : StackCursor,
87 +exports.reset = function<T>(
88 + cursor : StackCursor<T>,
89 ) : void {
90 while (index > -1) {
92 - valueStack[index] = emptyObject;
91 + valueStack[index] = null;
92
93 if (__DEV__) {
95 - fiberStack[index] = emptyObject;
94 + fiberStack[index] = null;
95 }
96
97 index--;
98 }
99
101 - cursor.current = null;
100 + cursor.current = (null : any);
101 };