stencil-quantum
Version:
Experience the quantum realm of stencil.
40 lines (39 loc) • 1.78 kB
TypeScript
import { HTMLStencilElement } from "../stencil-public-runtime";
export declare type ProvideCallback<T> = (newvalue: T, oldvalue?: T) => void;
export interface Listener<T> {
action: ProvideCallback<T>;
unlisten: Function;
paused: boolean;
}
export declare class Provider<T> {
readonly key: string | symbol;
private value;
debug: boolean;
listeners: Listener<T>[];
hooks: Map<HTMLStencilElement, Listener<T>>;
mutable: boolean;
paused: boolean;
constructor(key: string | symbol, value: T, debug?: boolean);
pause(paused?: boolean): void;
retrieve: () => T;
provide: (value: T) => this;
update: (fn: (v: T) => T) => this;
listen: (cb: ProvideCallback<T>, updateImmediately?: boolean, el?: HTMLStencilElement | undefined) => Listener<T>;
unlisten: (cb: ProvideCallback<T>) => void;
attach: <H extends boolean | undefined>(el: H extends true ? HTMLElement : HTMLStencilElement, noHook?: H | undefined) => this;
isHooked: (el: HTMLStencilElement) => boolean;
getHook: (el: HTMLStencilElement) => Listener<T> | undefined;
hook: (el: HTMLStencilElement) => this;
pauseHook: (el: HTMLStencilElement, paused?: boolean) => void;
unhook: (el: HTMLStencilElement) => this;
destroy: () => void;
/**
* Creates a predicate, that filters providers matching a key and having no namespace or being
* @param key
* @param namespace
*/
static makeFilter(key: string | symbol, namespace?: string): (p: Provider<any>) => boolean | "" | undefined;
static find<T>(el: HTMLElement, key: string | symbol, namespace?: string, debug?: boolean): Provider<T>;
static create<T>(el: HTMLStencilElement, key: string | symbol, value: T, namespace?: string, debug?: boolean): Provider<T>;
static getAttached(el: HTMLElement): Provider<any>[];
}