Add update functions on both Rivets.View and Rivets.Binding used for updating bi…
…ndings with a new set of models. [Closes #131]
Showing
1 changed file
with
13 additions
and
0 deletions
... | @@ -123,6 +123,13 @@ class Rivets.Binding | ... | @@ -123,6 +123,13 @@ class Rivets.Binding |
123 | 123 | ||
124 | @view.config.adapter.unsubscribe model, keypath, @sync | 124 | @view.config.adapter.unsubscribe model, keypath, @sync |
125 | 125 | ||
126 | # Updates the binding's model from what is currently set on the view. Unbinds | ||
127 | # the old model first and then re-binds with the new model. | ||
128 | update: => | ||
129 | @unbind() | ||
130 | @model = @view.models[@key] | ||
131 | @bind() | ||
132 | |||
126 | # A collection of bindings built from a set of parent elements. | 133 | # A collection of bindings built from a set of parent elements. |
127 | class Rivets.View | 134 | class Rivets.View |
128 | # The DOM elements and the model objects for binding are passed into the | 135 | # The DOM elements and the model objects for binding are passed into the |
... | @@ -222,6 +229,12 @@ class Rivets.View | ... | @@ -222,6 +229,12 @@ class Rivets.View |
222 | publish: => | 229 | publish: => |
223 | binding.publish() for binding in @select (b) -> b.binder.publishes | 230 | binding.publish() for binding in @select (b) -> b.binder.publishes |
224 | 231 | ||
232 | # Updates the view's models along with any affected bindings. | ||
233 | update: (models = {}) => | ||
234 | for key, model of models | ||
235 | @models[key] = model | ||
236 | binding.update() for binding in @select (b) -> b.key is key | ||
237 | |||
225 | # Cross-browser event binding. | 238 | # Cross-browser event binding. |
226 | bindEvent = (el, event, handler, context) -> | 239 | bindEvent = (el, event, handler, context) -> |
227 | fn = (e) -> handler.call context, e | 240 | fn = (e) -> handler.call context, e | ... | ... |
-
Please register or sign in to post a comment