1 | import { Binding } from './binding';
|
2 | import { BindingFilter } from './binding-filter';
|
3 | import { Context } from './context';
|
4 | import { 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 | */
|
9 | export 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 | */
|
16 | export type ContextObserverFn = (eventType: ContextEventType, binding: Readonly<Binding<unknown>>, context: Context) => ValueOrPromise<void>;
|
17 | /**
|
18 | * Observers of context bind/unbind events
|
19 | */
|
20 | export 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 | */
|
36 | export type ContextEventObserver = ContextObserver | ContextObserverFn;
|