MCPcopy Create free account
hub / github.com/krasimir/react-in-patterns / ReactFiberHostContext

Function ReactFiberHostContext

code/dependency-injection/public/app.js:11980–12061  ·  view source on GitHub ↗
(config, stack)

Source from the content-addressed store, hash-verified

11978var NO_CONTEXT = {};
11979
11980var ReactFiberHostContext = function (config, stack) {
11981 var getChildHostContext = config.getChildHostContext,
11982 getRootHostContext = config.getRootHostContext;
11983 var createCursor = stack.createCursor,
11984 push = stack.push,
11985 pop = stack.pop;
11986
11987
11988 var contextStackCursor = createCursor(NO_CONTEXT);
11989 var contextFiberStackCursor = createCursor(NO_CONTEXT);
11990 var rootInstanceStackCursor = createCursor(NO_CONTEXT);
11991
11992 function requiredContext(c) {
11993 !(c !== NO_CONTEXT) ? invariant(false, 'Expected host context to exist. This error is likely caused by a bug in React. Please file an issue.') : void 0;
11994 return c;
11995 }
11996
11997 function getRootHostContainer() {
11998 var rootInstance = requiredContext(rootInstanceStackCursor.current);
11999 return rootInstance;
12000 }
12001
12002 function pushHostContainer(fiber, nextRootInstance) {
12003 // Push current root instance onto the stack;
12004 // This allows us to reset root when portals are popped.
12005 push(rootInstanceStackCursor, nextRootInstance, fiber);
12006
12007 var nextRootContext = getRootHostContext(nextRootInstance);
12008
12009 // Track the context and the Fiber that provided it.
12010 // This enables us to pop only Fibers that provide unique contexts.
12011 push(contextFiberStackCursor, fiber, fiber);
12012 push(contextStackCursor, nextRootContext, fiber);
12013 }
12014
12015 function popHostContainer(fiber) {
12016 pop(contextStackCursor, fiber);
12017 pop(contextFiberStackCursor, fiber);
12018 pop(rootInstanceStackCursor, fiber);
12019 }
12020
12021 function getHostContext() {
12022 var context = requiredContext(contextStackCursor.current);
12023 return context;
12024 }
12025
12026 function pushHostContext(fiber) {
12027 var rootInstance = requiredContext(rootInstanceStackCursor.current);
12028 var context = requiredContext(contextStackCursor.current);
12029 var nextContext = getChildHostContext(context, fiber.type, rootInstance);
12030
12031 // Don't push this Fiber's context unless it's unique.
12032 if (context === nextContext) {
12033 return;
12034 }
12035
12036 // Track the context and the Fiber that provided it.
12037 // This enables us to pop only Fibers that provide unique contexts.

Callers 1

ReactFiberSchedulerFunction · 0.70

Calls 1

createCursorFunction · 0.70

Tested by

no test coverage detected