/* IMPORT */ import {CONTEXTS_DATA} from '~/constants'; import resolve from '~/methods/resolve'; import {context} from '~/oby'; import type {Child, Context, ContextWithDefault} from '~/types'; /* MAIN */ function createContext ( defaultValue: T ): ContextWithDefault; function createContext ( defaultValue?: T ): Context; function createContext ( defaultValue?: T ): ContextWithDefault | Context { const symbol = Symbol (); const Provider = ({ value, children }: { value: T, children: Child }): Child => { return context ( { [symbol]: value }, () => { return resolve ( children ); }); }; const Context = {Provider}; CONTEXTS_DATA.set ( Context, { symbol, defaultValue } ); return Context; } /* EXPORT */ export default createContext;