-
Notifications
You must be signed in to change notification settings - Fork 11
Binding
fastn bindings are the link between your data and your properties
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){ ... })
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'));
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.
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.
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.
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.
Returns whether the binding is destroyed
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.