bindable.Object


Bindable Objects are the base class for most components including views, and models.

Two-way data binding means linking properties of two separate objects - when one changes, the other will automatically update with that change. It enables much easier interactions between data models and UIs, among other uses outside of MVC.

Installation

npm install bindable --save-exact

Object(properties)

creates a new bindable object

value get(property)

Returns a property on the bindable object

set(property, value)

Sets a value to the bindable object

setProperties(properties)

sets multiple properties on the bindable object

has(property)

Returns true if the bindable object has a given property

listener on(event, callback)

adds a new listener to the bindable object

emit(event[,args...])

emits a new event

once(event, callback)

listens to one event, then disposes the listener.

removeAllListeners([type])

returns all the listeners on the bindable object

binding bind(from, options)

options - the options for the binding

  • to - the property to bind to. Can be a string, array, or function
  • target - the target bindable object. Default is self
  • max - max number of times to run the data-binding
  • when - tests the data-bound value before setting
  • map - transforms the data-bound value
  • bothWays - makes the data-binding bi-directional.

binding.now()

Executes a binding now

binding.dispose()

Disposes a binding

Events

Bindable objects emit a few events:

  • change:* - emitted when a property changes on the bindable object. E.g: change:location.zip.
  • change - emitted when any property changes on the bindable object
  • watching - emitted when a property is being watched
  • dispose - emitted when dispose() is called on a bindable object