966fa1ab by Michael Richards

Don't perform the unbind + bind on the binder when updating the models. Allow a …

…custom update function on binders instead for them to handle updates. [#183]
1 parent 38784e93
......@@ -137,10 +137,24 @@ class Rivets.Binding
# 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 = if @key then @view.models[@key] else @view.models
@bind()
update: (models = {}) =>
if @key
if models[@key]
unless @options.bypass
@view.config.adapter.unsubscribe @model, @keypath, @sync
@model = models[@key]
if @options.bypass
@sync()
else
@view.config.adapter.subscribe @model, @keypath, @sync
@sync() if @view.config.preloadData
@binder.update?.call @, models
else
@sync()
@binder.update?.call @, models
# Rivets.View
# -----------
......@@ -246,9 +260,8 @@ class Rivets.View
# 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
@models[key] = model for key, model of models
binding.update models for binding in @bindings
# Rivets.Util
# -----------
......