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 ...@@ -137,10 +137,24 @@ class Rivets.Binding
137 137
138 # Updates the binding's model from what is currently set on the view. Unbinds 138 # Updates the binding's model from what is currently set on the view. Unbinds
139 # the old model first and then re-binds with the new model. 139 # the old model first and then re-binds with the new model.
140 update: => 140 update: (models = {}) =>
141 @unbind() 141 if @key
142 @model = if @key then @view.models[@key] else @view.models 142 if models[@key]
143 @bind() 143 unless @options.bypass
144 @view.config.adapter.unsubscribe @model, @keypath, @sync
145
146 @model = models[@key]
147
148 if @options.bypass
149 @sync()
150 else
151 @view.config.adapter.subscribe @model, @keypath, @sync
152 @sync() if @view.config.preloadData
153
154 @binder.update?.call @, models
155 else
156 @sync()
157 @binder.update?.call @, models
144 158
145 # Rivets.View 159 # Rivets.View
146 # ----------- 160 # -----------
...@@ -246,9 +260,8 @@ class Rivets.View ...@@ -246,9 +260,8 @@ class Rivets.View
246 260
247 # Updates the view's models along with any affected bindings. 261 # Updates the view's models along with any affected bindings.
248 update: (models = {}) => 262 update: (models = {}) =>
249 for key, model of models 263 @models[key] = model for key, model of models
250 @models[key] = model 264 binding.update models for binding in @bindings
251 binding.update() for binding in @select (b) -> b.key is key
252 265
253 # Rivets.Util 266 # Rivets.Util
254 # ----------- 267 # -----------
......