UNPKG

@dnd-kit-svelte/svelte

Version:

[![Stable release](https://img.shields.io/npm/v/@dnd-kit-svelte/svelte.svg)](https://npm.im/@dnd-kit-svelte/svelte)

44 lines (43 loc) 1.53 kB
export declare class Context<TContext> { #private; /** * @param name The name of the context. * This is used for generating the context key and error messages. * @param fallback Optional fallback value to return when context doesn't exist. */ constructor(name: string, fallback?: TContext); /** * The key used to get and set the context. * * It is not recommended to use this value directly. * Instead, use the methods provided by this class. */ get key(): symbol; /** * Checks whether this has been set in the context of a parent component. * * Must be called during component initialisation. */ exists(): boolean; /** * Retrieves the context that belongs to the closest parent component. * * Must be called during component initialisation. * * @throws An error if the context does not exist. */ get(): TContext; /** * Retrieves the context that belongs to the closest parent component, * or the given fallback value if the context does not exist. * * Must be called during component initialisation. */ getOr<TFallback extends TContext | null | undefined = TContext>(fallback?: TFallback): (TContext & ({} | null)) | (TFallback extends null ? TContext | null : TContext); /** * Associates the given value with the current component and returns it. * * Must be called during component initialisation. */ set(context: TContext): TContext; }