8ba303c7 by Michael Richards

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

1 parent e7a734d3
...@@ -64,12 +64,14 @@ class Rivets.Binding ...@@ -64,12 +64,14 @@ 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 @reset = (value) =>
68 @set if @options.bypass
69 @model[@keypath]
70 else
71 Rivets.config.adapter.read @model, @keypath
72
67 for keypath in @options.dependencies 73 for keypath in @options.dependencies
68 Rivets.config.adapter.subscribe @model, keypath, (stub) => 74 Rivets.config.adapter.subscribe @model, keypath, @reset
69 @set if @options.bypass
70 @model[@keypath]
71 else
72 Rivets.config.adapter.read @model, @keypath
73 75
74 if @type in @bidirectionals 76 if @type in @bidirectionals
75 bindEvent @el, 'change', @publish 77 bindEvent @el, 'change', @publish
...@@ -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
......