/** * binding.ts offers a convenient subscribe() function that creates a binding to an observable, a * a plain value, or a function from which it builds a computed. */ import { IDisposable } from './dispose'; import { IKnockoutReadObservable, InferKoType } from './kowrap'; import { BaseObservable } from './observable'; import { UseCBOwner } from './subscribe'; /** * Any of the value types that DOM methods know how to subscribe to: a plain value (like a * string); an Observable (including a Computed); a knockout observable; a function. * * If a function, it's used to create a `Computed`, and will be called with a context function * `use`, allowing it to depend on other observable values (see documentation for `Computed`). */ export type BindableValue = BaseObservable | ComputedCallback | T | IKnockoutReadObservable; export type ComputedCallback = (use: UseCBOwner, ...args: any[]) => T; /** * Subscribes a callback to valueObs, which may be one a plain value, an observable, a knockout * observable, or a function. If a function, it's used to create a computed() and will be called * with a context function `use`, allowing it to depend on other observable values (see * documentation for `computed`). * * In all cases, `callback(newValue, oldValue)` is called immediately and whenever the value * changes. On the initial call, oldValue is undefined. * * Returns an object which should be disposed to remove the created subscriptions, or null. */ export declare function subscribeBindable>(valueObs: KObs, callback: (val: InferKoType) => void): IDisposable | null; export declare function subscribeBindable(valueObs: BindableValue, callback: (val: T) => void): IDisposable | null; /** * Subscribes a callback to `valueObs` (which may be a value, observable, or function) using * `subscribeBindable()`, and ties the disposal of this subscription to the passed-in element. */ export declare function subscribeElem(elem: Node, valueObs: BindableValue, callback: (newVal: T, oldVal?: T) => void): void;