Download packages/tui/src/context/helper.tsx from SaylorTwift/opencode: direct link, hf CLI and curl.
- Browser
- Download file 761 Bytes
-
https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/tui/src/context/helper.tsx
- Command line
-
hf download hf://SaylorTwift/opencode/packages/tui/src/context/helper.tsx
-
curl -L -o helper.tsx https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/tui/src/context/helper.tsx
761 Bytes
| import { createContext, Show, useContext, type ParentProps } from "solid-js" | |
| export function createSimpleContext<T, Props extends Record<string, any>>(input: { | |
| name: string | |
| init: ((input: Props) => T) | (() => T) | |
| }) { | |
| const ctx = createContext<T>() | |
| return { | |
| context: ctx, | |
| provider: (props: ParentProps<Props>) => { | |
| const init = input.init(props) | |
| return ( | |
| // @ts-expect-error | |
| <Show when={init.ready === undefined || init.ready === true}> | |
| <ctx.Provider value={init}>{props.children}</ctx.Provider> | |
| </Show> | |
| ) | |
| }, | |
| use() { | |
| const value = useContext(ctx) | |
| if (!value) throw new Error(`${input.name} context must be used within a context provider`) | |
| return value | |
| }, | |
| } | |
| } | |