UNPKG

simple-bound

Version:

A simple and customizable reactive data-binding library.

58 lines 2.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const boundError_1 = require("../boundError"); const config_1 = require("../config"); class BaseBound { /** * Creates an instance of BaseBound. * @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. */ constructor(proto, plugins) { this.plugins = plugins; /** * Stores bindings in a structure that is identical to the binding-prototype-object. */ this.storage = {}; /** * A bound object created from a constuctor's snapshot object. * * Contains an instance of the Bound class itself by the `__bound__` key. */ this.boundObject = { __bound__: this }; // Make __bound__ non-enumerable. Object.defineProperty(this.boundObject, '__bound__', { value: this, writable: true }); if (BaseBound.config.debug && typeof proto !== 'object') { throw new boundError_1.default('Only object binds are allowed. For property and pure value bindings use Binding from "bound/binding".'); } if (BaseBound.config.debug && proto instanceof BaseBound || BaseBound.isBound(proto)) { throw new boundError_1.default('Cannot rebind a bound object.'); } } /** * [NOT_IMPLEMENTED] Maps the object of a different shape to the original binding object * @param obj target object to bind * @param mapToOriginal a map for target object's keys relative to the original binding object type * @param twoWay whether the binding should be two-way */ bindAndMap(obj, mapToOriginal, twoWay) { throw new boundError_1.default('Method not implemented.'); } /** * Global binding config. Changes affect all instances. */ static get config() { return config_1.default; } /** * Checks whether an object is already bound. * * @param obj an object ot check */ static isBound(obj) { return !!obj.__bound__ && (obj.__bound__ instanceof BaseBound); } } exports.default = BaseBound; //# sourceMappingURL=base.js.map