UNPKG

context-protocol

Version:

A fully-typed implementation of the context-protocol, with support for subscriptions.

23 lines (22 loc) 1.54 kB
import type { Context, ContextCallback, ContextType, EventTargetConstructor, ExtractContext } from "./subscriptions.ts"; import { ContextRequestEvent, addContextListener, createContext, getContextValue, removeContextListener, setContextValue } from "./subscriptions.ts"; /** Mixin that allows the target to add a callback for a context. */ declare const ContextConsumerMixin: <T extends EventTargetConstructor>(Target: T) => T & ContextConsumerMixin.Constructor; declare namespace ContextConsumerMixin { interface Constructor extends EventTargetConstructor<Mixin> { } interface Mixin { addContextListener<T>(context: ExtractContext<T>, callback: ContextCallback<ContextType<T>>, subscribe?: boolean): void; removeContextListener<T>(context: ExtractContext<T>, callback: ContextCallback<ContextType<T>>): void; } } /** Mixin that allows the target to provide values to a context. */ declare const ContextProviderMixin: <T extends EventTargetConstructor>(Target: T) => T & ContextProviderMixin.Constructor; declare namespace ContextProviderMixin { interface Constructor extends EventTargetConstructor<Mixin> { } interface Mixin { setContextValue<T>(context: ExtractContext<T>, value: ContextType<T>): void; } } export { type Context, type ContextCallback, type ContextType, type EventTargetConstructor, type ExtractContext, ContextConsumerMixin, ContextProviderMixin, ContextRequestEvent, addContextListener, createContext, getContextValue, removeContextListener, setContextValue, };