ee557a0c by Michael Richards

Merge pull request #184 from mikeric/fix-nested-view-update-propogation

Fix nested view update propogation
2 parents 38784e93 8d1c2701
...@@ -137,10 +137,23 @@ class Rivets.Binding ...@@ -137,10 +137,23 @@ 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 else
154 @sync()
155
156 @binder.update?.call @, models
144 157
145 # Rivets.View 158 # Rivets.View
146 # ----------- 159 # -----------
...@@ -246,9 +259,8 @@ class Rivets.View ...@@ -246,9 +259,8 @@ class Rivets.View
246 259
247 # Updates the view's models along with any affected bindings. 260 # Updates the view's models along with any affected bindings.
248 update: (models = {}) => 261 update: (models = {}) =>
249 for key, model of models 262 @models[key] = model for key, model of models
250 @models[key] = model 263 binding.update models for binding in @bindings
251 binding.update() for binding in @select (b) -> b.key is key
252 264
253 # Rivets.Util 265 # Rivets.Util
254 # ----------- 266 # -----------
...@@ -396,6 +408,9 @@ Rivets.binders = ...@@ -396,6 +408,9 @@ Rivets.binders =
396 @nested.unbind() 408 @nested.unbind()
397 delete @nested 409 delete @nested
398 410
411 update: (models) ->
412 @nested.update models
413
399 unless: 414 unless:
400 block: true 415 block: true
401 416
...@@ -408,6 +423,9 @@ Rivets.binders = ...@@ -408,6 +423,9 @@ Rivets.binders =
408 routine: (el, value) -> 423 routine: (el, value) ->
409 Rivets.binders.if.routine.call @, el, not value 424 Rivets.binders.if.routine.call @, el, not value
410 425
426 update: (models) ->
427 Rivets.binders.if.update.call @, models
428
411 "on-*": 429 "on-*":
412 function: true 430 function: true
413 431
...@@ -474,6 +492,14 @@ Rivets.binders = ...@@ -474,6 +492,14 @@ Rivets.binders =
474 else if @iterated[index].models[modelName] isnt model 492 else if @iterated[index].models[modelName] isnt model
475 @iterated[index].update data 493 @iterated[index].update data
476 494
495 update: (models) ->
496 data = {}
497
498 for key, model of models
499 data[key] = model unless key is @args[0]
500
501 view.update data for view in @iterated
502
477 "class-*": (el, value) -> 503 "class-*": (el, value) ->
478 elClass = " #{el.className} " 504 elClass = " #{el.className} "
479 505
......