UNPKG

1.3 kBTypeScriptView Raw
1import { Binding } from './binding';
2import { BindingFilter } from './binding-filter';
3import { Context } from './context';
4import { ValueOrPromise } from './value-promise';
5/**
6 * Context event types. We support `bind` and `unbind` for now but
7 * keep it open for new types
8 */
9export type ContextEventType = 'bind' | 'unbind' | string;
10/**
11 * Listen on `bind`, `unbind`, or other events
12 * @param eventType - Context event type
13 * @param binding - The binding as event source
14 * @param context - Context object for the binding event
15 */
16export type ContextObserverFn = (eventType: ContextEventType, binding: Readonly<Binding<unknown>>, context: Context) => ValueOrPromise<void>;
17/**
18 * Observers of context bind/unbind events
19 */
20export interface ContextObserver {
21 /**
22 * An optional filter function to match bindings. If not present, the listener
23 * will be notified of all binding events.
24 */
25 filter?: BindingFilter;
26 /**
27 * Listen on `bind`, `unbind`, or other events
28 * @param eventType - Context event type
29 * @param binding - The binding as event source
30 */
31 observe: ContextObserverFn;
32}
33/**
34 * Context event observer type - An instance of `ContextObserver` or a function
35 */
36export type ContextEventObserver = ContextObserver | ContextObserverFn;