If the observer's target changes from the previous binding's @model value, recon…
…struct the dependency observers for the binding.
Showing
1 changed file
with
9 additions
and
1 deletions
... | @@ -58,7 +58,15 @@ class Rivets.Binding | ... | @@ -58,7 +58,15 @@ class Rivets.Binding |
58 | 58 | ||
59 | # Syncs up the view binding with the model. | 59 | # Syncs up the view binding with the model. |
60 | sync: => | 60 | sync: => |
61 | @model = @observer.target | 61 | if @model isnt @observer.target |
62 | observer.unobserve() for observer in @dependencies | ||
63 | @dependencies = [] | ||
64 | |||
65 | if (@model = @observer.target)? and @options.dependencies?.length | ||
66 | for dependency in @options.dependencies | ||
67 | observer = new Rivets.Observer @view, @model, dependency, @sync | ||
68 | @dependencies.push observer | ||
69 | |||
62 | @set @observer.value() | 70 | @set @observer.value() |
63 | 71 | ||
64 | # Publishes the value currently set on the input element back to the model. | 72 | # Publishes the value currently set on the input element back to the model. | ... | ... |
-
Please register or sign in to post a comment