MCPcopy
hub / github.com/anomalyco/opencode / createSimpleContext

Function createSimpleContext

packages/tui/src/context/helper.tsx:3–26  ·  view source on GitHub ↗
(input: {
  name: string
  init: ((input: Props) => T) | (() => T)
})

Source from the content-addressed store, hash-verified

1import { createContext, Show, useContext, type ParentProps } from "solid-js"
2
3export function createSimpleContext<T, Props extends Record<string, any>>(input: {
4 name: string
5 init: ((input: Props) => T) | (() => T)
6}) {
7 const ctx = createContext<T>()
8
9 return {
10 context: ctx,
11 provider: (props: ParentProps<Props>) => {
12 const init = input.init(props)
13 return (
14 // @ts-expect-error
15 <Show when={init.ready === undefined || init.ready === true}>
16 <ctx.Provider value={init}>{props.children}</ctx.Provider>
17 </Show>
18 )
19 },
20 use() {
21 const value = useContext(ctx)
22 if (!value) throw new Error(`${input.name} context must be used within a context provider`)
23 return value
24 },
25 }
26}

Callers 15

frecency.tsxFile · 0.90
history.tsxFile · 0.90
stash.tsxFile · 0.90
sync.tsxFile · 0.90
kv.tsxFile · 0.90
project.tsxFile · 0.90
sdk.tsxFile · 0.90
permission.tsxFile · 0.90
prompt.tsxFile · 0.90
route.tsxFile · 0.90
local.tsxFile · 0.90
exit.tsxFile · 0.90

Calls 1

initMethod · 0.45

Tested by

no test coverage detected