summaryrefslogtreecommitdiffhomepage
path: root/cloud/web/src/util
diff options
context:
space:
mode:
authorFrank <[email protected]>2025-08-08 13:22:54 -0400
committerFrank <[email protected]>2025-08-08 13:24:32 -0400
commit183e0911b76025a1f2a82e979d9834fec2131d0e (patch)
tree9987c1753bd64d1ce1d174ab397f1a8c681f642c /cloud/web/src/util
parentc7bb19ad0712469063eab35589aa5d3602b0c5b1 (diff)
downloadopencode-183e0911b76025a1f2a82e979d9834fec2131d0e.tar.gz
opencode-183e0911b76025a1f2a82e979d9834fec2131d0e.zip
wip: gateway
Diffstat (limited to 'cloud/web/src/util')
-rw-r--r--cloud/web/src/util/context.tsx26
1 files changed, 26 insertions, 0 deletions
diff --git a/cloud/web/src/util/context.tsx b/cloud/web/src/util/context.tsx
new file mode 100644
index 000000000..d1c6f4e7f
--- /dev/null
+++ b/cloud/web/src/util/context.tsx
@@ -0,0 +1,26 @@
+import { ParentProps, Show, createContext, useContext } from "solid-js"
+
+export function createInitializedContext<
+ Name extends string,
+ T extends { ready: boolean },
+>(name: Name, cb: () => T) {
+ const ctx = createContext<T>()
+
+ return {
+ use: () => {
+ const context = useContext(ctx)
+ if (!context) throw new Error(`No ${name} context`)
+ return context
+ },
+ provider: (props: ParentProps) => {
+ const value = cb()
+ return (
+ <Show when={value.ready}>
+ <ctx.Provider value={value} {...props}>
+ {props.children}
+ </ctx.Provider>
+ </Show>
+ )
+ },
+ }
+}