Make sure that we unbind and re-bind any dependencies when the model changes for a binding.
Showing
1 changed file
with
7 additions
and
7 deletions
... | @@ -49,9 +49,9 @@ class Rivets.Binding | ... | @@ -49,9 +49,9 @@ class Rivets.Binding |
49 | model = current | 49 | model = current |
50 | 50 | ||
51 | if @key and @model and @model isnt model | 51 | if @key and @model and @model isnt model |
52 | @view.adapters[@key.interface].unsubscribe @model, @key.path, @sync | 52 | @unbind true |
53 | @view.adapters[@key.interface].subscribe model, @key.path, @sync | ||
54 | @model = model | 53 | @model = model |
54 | @bind true | ||
55 | @sync() | 55 | @sync() |
56 | else | 56 | else |
57 | @model = model | 57 | @model = model |
... | @@ -113,10 +113,10 @@ class Rivets.Binding | ... | @@ -113,10 +113,10 @@ class Rivets.Binding |
113 | # Subscribes to the model for changes at the specified keypath. Bi-directional | 113 | # Subscribes to the model for changes at the specified keypath. Bi-directional |
114 | # routines will also listen for changes on the element to propagate them back | 114 | # routines will also listen for changes on the element to propagate them back |
115 | # to the model. | 115 | # to the model. |
116 | bind: => | 116 | bind: (silent = false) => |
117 | @binder.bind?.call @, @el | 117 | @binder.bind?.call @, @el unless silent |
118 | @view.adapters[@key.interface].subscribe(@model, @key.path, @sync) if @key | 118 | @view.adapters[@key.interface].subscribe(@model, @key.path, @sync) if @key |
119 | @sync() if @view.config.preloadData | 119 | @sync() if @view.config.preloadData unless silent |
120 | 120 | ||
121 | if @options.dependencies?.length | 121 | if @options.dependencies?.length |
122 | for dependency in @options.dependencies | 122 | for dependency in @options.dependencies |
... | @@ -136,8 +136,8 @@ class Rivets.Binding | ... | @@ -136,8 +136,8 @@ class Rivets.Binding |
136 | @dependencies.push [model, key] | 136 | @dependencies.push [model, key] |
137 | 137 | ||
138 | # Unsubscribes from the model and the element. | 138 | # Unsubscribes from the model and the element. |
139 | unbind: => | 139 | unbind: (silent = false) => |
140 | @binder.unbind?.call @, @el | 140 | @binder.unbind?.call @, @el unless silent |
141 | @view.adapters[@key.interface].unsubscribe(@model, @key.path, @sync) if @key | 141 | @view.adapters[@key.interface].unsubscribe(@model, @key.path, @sync) if @key |
142 | 142 | ||
143 | if @dependencies.length | 143 | if @dependencies.length | ... | ... |
-
Please register or sign in to post a comment