Move bidirectional binding/unbinding into proper context. Make sure that bypasse…
…d bindings with dependencies will get unbinded properly.
Showing
1 changed file
with
6 additions
and
5 deletions
... | @@ -78,6 +78,9 @@ class Rivets.Binding | ... | @@ -78,6 +78,9 @@ class Rivets.Binding |
78 | Rivets.config.adapter.subscribe @model, @keypath, @sync | 78 | Rivets.config.adapter.subscribe @model, @keypath, @sync |
79 | @sync() if Rivets.config.preloadData | 79 | @sync() if Rivets.config.preloadData |
80 | 80 | ||
81 | if @isBidirectional() | ||
82 | bindEvent @el, 'change', @publish | ||
83 | |||
81 | if @options.dependencies?.length | 84 | if @options.dependencies?.length |
82 | for dependency in @options.dependencies | 85 | for dependency in @options.dependencies |
83 | if /^\./.test dependency | 86 | if /^\./.test dependency |
... | @@ -90,21 +93,19 @@ class Rivets.Binding | ... | @@ -90,21 +93,19 @@ class Rivets.Binding |
90 | 93 | ||
91 | Rivets.config.adapter.subscribe model, keypath, @sync | 94 | Rivets.config.adapter.subscribe model, keypath, @sync |
92 | 95 | ||
93 | if @isBidirectional() and not @options.bypass | ||
94 | bindEvent @el, 'change', @publish | ||
95 | 96 | ||
96 | # Unsubscribes from the model and the element. | 97 | # Unsubscribes from the model and the element. |
97 | unbind: => | 98 | unbind: => |
98 | unless @options.bypass | 99 | unless @options.bypass |
99 | Rivets.config.adapter.unsubscribe @model, @keypath, @sync | 100 | Rivets.config.adapter.unsubscribe @model, @keypath, @sync |
100 | 101 | ||
102 | if @isBidirectional() | ||
103 | @el.removeEventListener 'change', @publish | ||
104 | |||
101 | if @options.dependencies?.length | 105 | if @options.dependencies?.length |
102 | for keypath in @options.dependencies | 106 | for keypath in @options.dependencies |
103 | Rivets.config.adapter.unsubscribe @model, keypath, @sync | 107 | Rivets.config.adapter.unsubscribe @model, keypath, @sync |
104 | 108 | ||
105 | if @isBidirectional() | ||
106 | @el.removeEventListener 'change', @publish | ||
107 | |||
108 | # A collection of bindings built from a set of parent elements. | 109 | # A collection of bindings built from a set of parent elements. |
109 | class Rivets.View | 110 | class Rivets.View |
110 | # The DOM elements and the model objects for binding are passed into the | 111 | # The DOM elements and the model objects for binding are passed into the | ... | ... |
-
Please register or sign in to post a comment