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

Function ReactFiberHostContext

code/composition/public/app.js:12025–12106  ·  view source on GitHub ↗
(config, stack)

Source from the content-addressed store, hash-verified

12023var NO_CONTEXT = {};
12024
12025var ReactFiberHostContext = function (config, stack) {
12026 var getChildHostContext = config.getChildHostContext,
12027 getRootHostContext = config.getRootHostContext;
12028 var createCursor = stack.createCursor,
12029 push = stack.push,
12030 pop = stack.pop;
12031
12032
12033 var contextStackCursor = createCursor(NO_CONTEXT);
12034 var contextFiberStackCursor = createCursor(NO_CONTEXT);
12035 var rootInstanceStackCursor = createCursor(NO_CONTEXT);
12036
12037 function requiredContext(c) {
12038 !(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;
12039 return c;
12040 }
12041
12042 function getRootHostContainer() {
12043 var rootInstance = requiredContext(rootInstanceStackCursor.current);
12044 return rootInstance;
12045 }
12046
12047 function pushHostContainer(fiber, nextRootInstance) {
12048 // Push current root instance onto the stack;
12049 // This allows us to reset root when portals are popped.
12050 push(rootInstanceStackCursor, nextRootInstance, fiber);
12051
12052 var nextRootContext = getRootHostContext(nextRootInstance);
12053
12054 // Track the context and the Fiber that provided it.
12055 // This enables us to pop only Fibers that provide unique contexts.
12056 push(contextFiberStackCursor, fiber, fiber);
12057 push(contextStackCursor, nextRootContext, fiber);
12058 }
12059
12060 function popHostContainer(fiber) {
12061 pop(contextStackCursor, fiber);
12062 pop(contextFiberStackCursor, fiber);
12063 pop(rootInstanceStackCursor, fiber);
12064 }
12065
12066 function getHostContext() {
12067 var context = requiredContext(contextStackCursor.current);
12068 return context;
12069 }
12070
12071 function pushHostContext(fiber) {
12072 var rootInstance = requiredContext(rootInstanceStackCursor.current);
12073 var context = requiredContext(contextStackCursor.current);
12074 var nextContext = getChildHostContext(context, fiber.type, rootInstance);
12075
12076 // Don't push this Fiber's context unless it's unique.
12077 if (context === nextContext) {
12078 return;
12079 }
12080
12081 // Track the context and the Fiber that provided it.
12082 // 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