01c164b5 by Michael Richards

Add update functions on both Rivets.View and Rivets.Binding used for updating bi…

…ndings with a new set of models. [Closes #131]
1 parent 750f8b73
......@@ -123,6 +123,13 @@ class Rivets.Binding
@view.config.adapter.unsubscribe model, keypath, @sync
# Updates the binding's model from what is currently set on the view. Unbinds
# the old model first and then re-binds with the new model.
update: =>
@unbind()
@model = @view.models[@key]
@bind()
# A collection of bindings built from a set of parent elements.
class Rivets.View
# The DOM elements and the model objects for binding are passed into the
......@@ -222,6 +229,12 @@ class Rivets.View
publish: =>
binding.publish() for binding in @select (b) -> b.binder.publishes
# Updates the view's models along with any affected bindings.
update: (models = {}) =>
for key, model of models
@models[key] = model
binding.update() for binding in @select (b) -> b.key is key
# Cross-browser event binding.
bindEvent = (el, event, handler, context) ->
fn = (e) -> handler.call context, e
......