context_helpers.ts

view source

Declarations
#

create_context
#

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 () => T

overloads

<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 () => T
returns { 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>
T

Imported by
#