UNPKG

@joist/di

Version:

Dependency Injection for Vanilla JS classes

19 lines (18 loc) 841 B
export type Context<KeyType, ValueType> = KeyType & { __context__: ValueType; }; export type UnknownContext = Context<unknown, unknown>; export type ContextType<T extends UnknownContext> = T extends Context<infer _, infer V> ? V : never; export declare function createContext<KeyType, ValueType>(key: KeyType): Context<KeyType, ValueType>; export type ContextCallback<ValueType> = (value: ValueType, unsubscribe?: () => void) => void; export declare class ContextRequestEvent<T extends UnknownContext> extends Event { context: T; callback: ContextCallback<ContextType<T>>; subscribe?: boolean; constructor(context: T, callback: ContextCallback<ContextType<T>>, subscribe?: boolean); } declare global { interface HTMLElementEventMap { "context-request": ContextRequestEvent<Context<unknown, unknown>>; } }