{"version":3,"file":"createStoreContext.cjs","names":["createContext","useContext","JSX","ParentProps","createStoreContext","StoreProvider","props","value","TValue","Element","useStoreContext","Context","_$createComponent","Provider","children","undefined","Error"],"sources":["../src/createStoreContext.tsx"],"sourcesContent":["import { createContext, useContext } from 'solid-js'\nimport type { JSX, ParentProps } from 'solid-js'\n\n/**\n * Creates a typed Solid context for sharing a bundle of atoms and stores with a\n * subtree.\n *\n * The returned `StoreProvider` only transports the provided object through\n * Solid context. Consumers destructure the contextual atoms and stores, then\n * compose them with the existing hooks like {@link useSelector} and\n * {@link useAtom}.\n *\n * The object shape is preserved exactly, so keyed atoms and stores remain fully\n * typed when read back with `useStoreContext()`.\n *\n * @example\n * ```tsx\n * const { StoreProvider, useStoreContext } = createStoreContext<{\n *   countAtom: Atom<number>\n *   totalsStore: Store<{ count: number }>\n * }>()\n *\n * function CountButton() {\n *   const { countAtom, totalsStore } = useStoreContext()\n *   const count = useSelector(countAtom)\n *   const total = useSelector(totalsStore, (state) => state.count)\n *\n *   return (\n *     <button\n *       type=\"button\"\n *       onClick={() =>\n *         totalsStore.setState((state) => ({ ...state, count: state.count + 1 }))\n *       }\n *     >\n *       {count()} / {total()}\n *     </button>\n *   )\n * }\n * ```\n *\n * @throws When `useStoreContext()` is called outside the matching `StoreProvider`.\n */\nexport function createStoreContext<TValue extends object>(): {\n  StoreProvider: (props: ParentProps<{ value: TValue }>) => JSX.Element\n  useStoreContext: () => TValue\n} {\n  const Context = createContext<TValue>()\n\n  function StoreProvider(props: ParentProps<{ value: TValue }>) {\n    return (\n      <Context.Provider value={props.value}>{props.children}</Context.Provider>\n    )\n  }\n\n  function useStoreContext(): TValue {\n    const value = useContext(Context)\n\n    if (value === undefined) {\n      throw new Error('Missing StoreProvider for StoreContext')\n    }\n\n    return value\n  }\n\n  return {\n    StoreProvider,\n    useStoreContext,\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,SAAgBI,qBAGd;CACA,MAAMO,uCAAiC;CAEvC,SAASN,cAAcC,OAAuC;AAC5D,2CACGK,QAAQE,UAAQ;GAAA,IAACN,QAAK;AAAA,WAAED,MAAMC;;GAAK,IAAAO,WAAA;AAAA,WAAGR,MAAMQ;;GAAQ,CAAA;;CAIzD,SAASJ,kBAA0B;EACjC,MAAMH,iCAAmBI,QAAQ;AAEjC,MAAIJ,UAAUQ,OACZ,OAAM,IAAIC,MAAM,yCAAyC;AAG3D,SAAOT;;AAGT,QAAO;EACLF;EACAK;EACD"}