UNPKG

simple-bound

Version:

A simple and customizable reactive data-binding library.

34 lines (33 loc) 1.48 kB
import Binding from '../binding'; import BaseBound, { IBoundPluginMap } from './base'; export declare type ISimpleBindingStorage<T extends object> = { [key in keyof T]: T[key] extends object ? ISimpleBindingStorage<T[key]> : Binding<T[key]>; }; /** * Allows multiple full-object bindings. * Stores bindings and binds objects together, providing the highest possible abstraction level for bindings. * * @extends {BaseBound<T>} * @template T captures a type of proto object for later usage in binding type inference */ export default class Bound<T extends object> extends BaseBound<T> { storage: ISimpleBindingStorage<T>; /** * Creates an instance of Bound using a proto object. * @param proto used as an object prototype for the creation of boundObject and storage. Doesn't become bound itself. * @param [plugins] to plug into the binding events. Do not work yet. */ constructor(proto: T, plugins?: IBoundPluginMap<T>); /** * Binds an object to all other current subscribers * * @template U used to capture the bound object type. Must extends original template type. * @param obj to bind * @param [twoWay] whether the binding should be two-way */ bind<U extends T>(obj: U, twoWay?: boolean): this; /** * Unbinds an object and destroys all of its listeners * * @param obj reference of object to be unbound */ unbind<U extends T>(obj: U): any; }