Avoid reading the same StackCursor current multiple times
Brian Vaughn committed
Dec 21, 2016 at 14:06 UTC
1148e827b9b97cfa2194c1a9d5d285e1ab3d89d2
1 file changed
+8
-7
src/renderers/shared/fiber/ReactFiberHostContext.js
+8
-7
@@ -48,10 +48,11 @@ module.exports = function<T, P, I, TI, C, CX>(
48
let rootInstanceStackCursor : StackCursor<?C> = createCursor((null: ?C));
49
50
function getRootHostContainer() : C {
51
- if (rootInstanceStackCursor.current == null) {
51
+ const rootInstance = rootInstanceStackCursor.current;
52
+ if (rootInstance == null) {
53
throw new Error('Expected root container to exist.');
54
}
54
- return rootInstanceStackCursor.current;
55
+ return rootInstance;
56
}
57
58
function pushHostContainer(fiber : Fiber, nextRootInstance : C) {
@@ -74,20 +75,20 @@ module.exports = function<T, P, I, TI, C, CX>(
75
}
76
77
function getHostContext() : CX {
77
- if (contextStackCursor.current == null) {
78
+ const context = contextStackCursor.current;
79
+ if (context == null) {
80
throw new Error('Expected host context to exist.');
81
}
80
-
81
- return contextStackCursor.current;
82
+ return context;
83
}
84
85
function pushHostContext(fiber : Fiber) : void {
85
- if (rootInstanceStackCursor.current == null) {
86
+ const rootInstance = rootInstanceStackCursor.current;
87
+ if (rootInstance == null) {
88
throw new Error('Expected root host context to exist.');
89
}
90
91
const context = contextStackCursor.current || emptyObject;
90
- const rootInstance = rootInstanceStackCursor.current;
92
const nextContext = getChildHostContext(context, fiber.type, rootInstance);
93
94
// Don't push this Fiber's context unless it's unique.