context_helpers.ts view source
<T>(fallback: () => T): { get: () => T; set: (value?: T | undefined) => T; } import {create_context} from '@fuzdev/fuz_ui/context_helpers.js'; Wraps Svelte's setContext and getContext for better ergonomics.
When no value is set in the context,
get throws an error and get_maybe returns undefined.
If a fallback is provided, the value argument to set is optional
and get_maybe is omitted from the type.
fallback
type
() => Toverloads
<T>(fallback: () => T): { get: () => T; set: (value?: T | undefined) => T; } Wraps Svelte's setContext and getContext for better ergonomics.
When no value is set in the context,
get throws an error and get_maybe returns undefined.
If a fallback is provided, the value argument to set is optional
and get_maybe is omitted from the type.
fallback () => Treturns
{ get: () => T; set: (value?: T | undefined) => T; }<T>(): { get: (error_message?: string | undefined) => T; get_maybe: () => T | undefined; set: (value: T) => T; } returns
{ get: (error_message?: string | undefined) => T; get_maybe: () => T | undefined; set: (value: T) => T; }returns
{ get: () => T; set: (value?: T | undefined) => T; } generics
create_context<T>