Skip to content
Kory Nunn edited this page Sep 18, 2015 · 3 revisions

fastn bindings are the link between your data and your properties

API

Create:

var someBinding = fastn.binding('key')

Set value: (emits 'change')

someBinding('foo'); -> binding

Get value:

someBinding(); -> 'foo'

Manually watch for changes:

someBinding.on('change', function(bindingValue){ ... })

usage on a property:

Properties can be assigned bindings, and will have their value updated when the binding changes:

// Automatic binding allocation:

var aComponent = fastn('div', {
    someProperty: fastn.binding('key') // someProperty will be assigned the 'key' binding.
});
// Manually
var someProperty = fastn.property();

someProperty.binding(fastn.binding('key'));

Tracking Changes

fastn bindings take a path, which is where in their attached data they are bound to. Any fastn.Model path is valid for a binding.

bindings use Enti models under the covers, and documentation for the path syntax can be found there.

Methods

attach(object or Model, firmness) -> binding

Attaches the binding to the provided object.

If a Model is passed, attach will use the object that the model is currently attached to, and bind events to the model to listen to future attaches.

If a firmness is provided, the binding will only be attached if the firmness is equal to or higher than that which it is currently attached at.

Returns the binding.

detach(firmess) -> binding

Detaches the binding from the model it is attached to

If a firmness is provided, the binding will only be detached if the firmness is equal to or higher than that which it is currently attached at.

Returns the binding.

destroy(optional soft) -> binding

Destroys a binding, potentially freeing memory and removing event handlers.

if a truthy value is passed as soft, the binding will only be destroyed if it has nothing listing to its change event.

Returns the binding.

destroyed() -> boolean

Returns whether the binding is destroyed

clone(optional keepAttachment) -> cloned binding

creates a new binding that is a clone of the original.

if a truthy value is passed as keepAttachment, the new binding will be attached to the same data as the original binding.

Returns the cloned binding.