8ba303c7 by Michael Richards

Make sure all dependency observers get unbinded when calling Rivets.Binding::unbind().

1 parent e7a734d3
...@@ -64,13 +64,15 @@ class Rivets.Binding ...@@ -64,13 +64,15 @@ class Rivets.Binding
64 @set Rivets.config.adapter.read @model, @keypath 64 @set Rivets.config.adapter.read @model, @keypath
65 65
66 if @options.dependencies?.length 66 if @options.dependencies?.length
67 for keypath in @options.dependencies 67 @reset = (value) =>
68 Rivets.config.adapter.subscribe @model, keypath, (stub) =>
69 @set if @options.bypass 68 @set if @options.bypass
70 @model[@keypath] 69 @model[@keypath]
71 else 70 else
72 Rivets.config.adapter.read @model, @keypath 71 Rivets.config.adapter.read @model, @keypath
73 72
73 for keypath in @options.dependencies
74 Rivets.config.adapter.subscribe @model, keypath, @reset
75
74 if @type in @bidirectionals 76 if @type in @bidirectionals
75 bindEvent @el, 'change', @publish 77 bindEvent @el, 'change', @publish
76 78
...@@ -83,6 +85,10 @@ class Rivets.Binding ...@@ -83,6 +85,10 @@ class Rivets.Binding
83 unbind: => 85 unbind: =>
84 Rivets.config.adapter.unsubscribe @model, @keypath, @set 86 Rivets.config.adapter.unsubscribe @model, @keypath, @set
85 87
88 if @options.dependencies?.length
89 for keypath in @options.dependencies
90 Rivets.config.adapter.unsubscribe @model, keypath, @reset
91
86 if @type in @bidirectionals 92 if @type in @bidirectionals
87 @el.removeEventListener 'change', @publish 93 @el.removeEventListener 'change', @publish
88 94
......