MCPcopy Create free account
hub / github.com/microsoft/SandDance / createContext

Function createContext

docs/external/js/react.development.js:1344–1450  ·  view source on GitHub ↗
(defaultValue, calculateChangedBits)

Source from the content-addressed store, hash-verified

1342 }
1343
1344 function createContext(defaultValue, calculateChangedBits) {
1345 if (calculateChangedBits === undefined) {
1346 calculateChangedBits = null;
1347 } else {
1348 {
1349 if (calculateChangedBits !== null && typeof calculateChangedBits !== 'function') {
1350 error('createContext: Expected the optional second argument to be a ' + 'function. Instead received: %s', calculateChangedBits);
1351 }
1352 }
1353 }
1354
1355 var context = {
1356 $$typeof: REACT_CONTEXT_TYPE,
1357 _calculateChangedBits: calculateChangedBits,
1358 // As a workaround to support multiple concurrent renderers, we categorize
1359 // some renderers as primary and others as secondary. We only expect
1360 // there to be two concurrent renderers at most: React Native (primary) and
1361 // Fabric (secondary); React DOM (primary) and React ART (secondary).
1362 // Secondary renderers store their context values on separate fields.
1363 _currentValue: defaultValue,
1364 _currentValue2: defaultValue,
1365 // Used to track how many concurrent renderers this context currently
1366 // supports within in a single renderer. Such as parallel server rendering.
1367 _threadCount: 0,
1368 // These are circular
1369 Provider: null,
1370 Consumer: null
1371 };
1372 context.Provider = {
1373 $$typeof: REACT_PROVIDER_TYPE,
1374 _context: context
1375 };
1376 var hasWarnedAboutUsingNestedContextConsumers = false;
1377 var hasWarnedAboutUsingConsumerProvider = false;
1378
1379 {
1380 // A separate object, but proxies back to the original context object for
1381 // backwards compatibility. It has a different $$typeof, so we can properly
1382 // warn for the incorrect usage of Context as a Consumer.
1383 var Consumer = {
1384 $$typeof: REACT_CONTEXT_TYPE,
1385 _context: context,
1386 _calculateChangedBits: context._calculateChangedBits
1387 }; // $FlowFixMe: Flow complains about not setting a value, which is intentional here
1388
1389 Object.defineProperties(Consumer, {
1390 Provider: {
1391 get: function () {
1392 if (!hasWarnedAboutUsingConsumerProvider) {
1393 hasWarnedAboutUsingConsumerProvider = true;
1394
1395 error('Rendering <Context.Consumer.Provider> is not supported and will be removed in ' + 'a future major release. Did you mean to render <Context.Provider> instead?');
1396 }
1397
1398 return context.Provider;
1399 },
1400 set: function (_Provider) {
1401 context.Provider = _Provider;

Callers

nothing calls this directly

Calls 1

errorFunction · 0.70

Tested by

no test coverage detected