@zedux/react
Version:
A Molecular State Engine for React
21 lines (20 loc) • 858 B
JavaScript
import { createContext } from 'react';
export const ecosystemContext = createContext('@@global');
/**
* These are copied from packages/atoms/src/utils/general.ts
*
* IMPORTANT: keep these in-sync with the ones in the atoms package
*/
export const Explicit = 1;
export const External = 2;
export const Static = 4;
// export const Deferred = 8
export const destroyed = Symbol.for(`@@zedux/destroyed`);
export const getReactContext = (ecosystem, atom) => {
var _a, _b;
const reactStorage = ((_a = ecosystem._storage).react || (_a.react = {}));
const contexts = (reactStorage.contexts || (reactStorage.contexts = new WeakMap()));
const windowContexts = contexts.get(createContext) ||
contexts.set(createContext, {}).get(createContext);
return (windowContexts[_b = atom.key] || (windowContexts[_b] = createContext(undefined)));
};