Skip to content

Instantly share code, notes, and snippets.

@mikeric
Created August 29, 2012 05:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeric/3507045 to your computer and use it in GitHub Desktop.
Save mikeric/3507045 to your computer and use it in GitHub Desktop.
Rivets.js grammar in binding declarations

1. Binding to an object's attribute.

obj.attribute

On bind, performs the binding routine using adapter.read on the attribute if preloadData is set to true. Then calls adapter.subscribe on the attribute.

2. Binding to an object's property.

obj:property

On bind, performs the binding routine using the value (or return value) of obj.property.

3. Binding to an object's attribute/property and specifying dependent attributes to observe.

obj.attribute < dep1
obj:property < dep1 dep2

On bind, performs the standard attribute/property binding (1/2). Then observes all the dependent attributes for changes, which will reperform the binding routine for the original attribute/property.

4. Binding to an object's attribute/property and specifying formatters (optionally with white-space delimited arguments).

obj.attribute | formatter1
obj.attribute | formatter1 200
obj:property | formatter1 | formatter2

On bind, performs the standard attribute/property binding, but runs the value through the formatters before performing the routine. Rivets.js first looks for formatters on the model object, and then on the rivets.formatters object.

5. Binding to an object's attribute/property and specifying dependent attributes to observe as well as formatters.

obj.attribute < dep1 dep2 | formatter1
obj:attribute < dep1 | formatter1 | formatter2

On bind, performs the same binding as (3) then later applies the formatters to the value as in (4).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment