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

This commit is contained in:
Brian Vaughn
2016-12-21 15:11:49 -08:00
parent 3d0cf47d26
commit a0902fc306
3 changed files with 26 additions and 24 deletions
@@ -36,11 +36,11 @@ if (__DEV__) {
var checkReactTypeSpec = require('checkReactTypeSpec');
}
let contextStackCursor : StackCursor = createCursor();
let didPerformWorkStackCursor : StackCursor = createCursor();
let contextStackCursor : StackCursor<?Object> = createCursor((null: ?Object));
let didPerformWorkStackCursor : StackCursor<?boolean> = createCursor((null: ?boolean));
function getUnmaskedContext() {
return contextStackCursor.current;
return contextStackCursor.current || emptyObject;
}
exports.getMaskedContext = function(workInProgress : Fiber) {
@@ -52,6 +52,7 @@ exports.getMaskedContext = function(workInProgress : Fiber) {
const unmaskedContext = getUnmaskedContext();
const context = {};
for (let key in contextTypes) {
context[key] = unmaskedContext[key];
}
@@ -16,6 +16,8 @@ import type { Fiber } from 'ReactFiber';
import type { HostConfig } from 'ReactFiberReconciler';
import type { StackCursor } from 'ReactFiberStack';
const emptyObject = require('emptyObject');
const {
createCursor,
pop,
@@ -41,8 +43,8 @@ module.exports = function<T, P, I, TI, C, CX>(
getRootHostContext,
} = config;
let contextStackCursor : StackCursor = createCursor();
let rootInstanceStackCursor : StackCursor = createCursor();
let contextStackCursor : StackCursor<?CX> = createCursor((null: ?CX));
let rootInstanceStackCursor : StackCursor<?C> = createCursor((null: ?C));
function getRootHostContainer() : C {
if (rootInstanceStackCursor.current == null) {
@@ -81,7 +83,7 @@ module.exports = function<T, P, I, TI, C, CX>(
throw new Error('Expected root host context to exist.');
}
const context = contextStackCursor.current;
const context = contextStackCursor.current || emptyObject;
const rootInstance = rootInstanceStackCursor.current;
const nextContext = getChildHostContext(context, fiber.type, rootInstance);
+17 -18
View File
@@ -14,14 +14,13 @@
import type { Fiber } from 'ReactFiber';
export type StackCursor = {|
current: any
export type StackCursor<T> = {|
current: T
|};
const emptyObject = require('emptyObject');
const warning = require('warning');
const valueStack : Array<Object> = [];
const valueStack : Array<any> = [];
if (__DEV__) {
var fiberStack : Array<Fiber | null> = [];
@@ -29,9 +28,9 @@ if (__DEV__) {
let index = -1;
exports.createCursor = function() : StackCursor {
exports.createCursor = function<T>(defaultValue : T) : StackCursor<T> {
return {
current: null,
current: defaultValue,
};
};
@@ -39,8 +38,8 @@ exports.isEmpty = function() : boolean {
return index === -1;
};
exports.pop = function(
cursor : StackCursor,
exports.pop = function<T>(
cursor : StackCursor<T>,
fiber: Fiber | null, // TODO (bvaughn) Tighten up this type to only accept Fiber
) : void {
if (index < 0) {
@@ -56,21 +55,21 @@ exports.pop = function(
}
}
valueStack[index] = emptyObject;
valueStack[index] = null;
if (__DEV__) {
fiberStack[index] = emptyObject;
fiberStack[index] = null;
}
index--;
cursor.current = index > -1
? valueStack[index]
: null;
: (null : any);
};
exports.push = function(
cursor : StackCursor,
exports.push = function<T>(
cursor : StackCursor<T>,
value : any,
fiber: Fiber | null, // TODO (bvaughn) Tighten up this type to only accept Fiber
) : void {
@@ -85,18 +84,18 @@ exports.push = function(
}
};
exports.reset = function(
cursor : StackCursor,
exports.reset = function<T>(
cursor : StackCursor<T>,
) : void {
while (index > -1) {
valueStack[index] = emptyObject;
valueStack[index] = null;
if (__DEV__) {
fiberStack[index] = emptyObject;
fiberStack[index] = null;
}
index--;
}
cursor.current = null;
cursor.current = (null : any);
};