Implement a separate callback space so that setting callback.wrapped in adapter.…
…subscribe won't overwrite the existing wrapped function, making the binding unbindable.
Showing
1 changed file
with
7 additions
and
4 deletions
... | @@ -64,14 +64,16 @@ class Rivets.Binding | ... | @@ -64,14 +64,16 @@ 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) => | 67 | @dependencyCallbacks = {} |
68 | |||
69 | for keypath in @options.dependencies | ||
70 | callback = @dependencyCallbacks[keypath] = (value) => | ||
68 | @set if @options.bypass | 71 | @set if @options.bypass |
69 | @model[@keypath] | 72 | @model[@keypath] |
70 | else | 73 | else |
71 | Rivets.config.adapter.read @model, @keypath | 74 | Rivets.config.adapter.read @model, @keypath |
72 | 75 | ||
73 | for keypath in @options.dependencies | 76 | Rivets.config.adapter.subscribe @model, keypath, callback |
74 | Rivets.config.adapter.subscribe @model, keypath, @reset | ||
75 | 77 | ||
76 | if @type in @bidirectionals | 78 | if @type in @bidirectionals |
77 | bindEvent @el, 'change', @publish | 79 | bindEvent @el, 'change', @publish |
... | @@ -87,7 +89,8 @@ class Rivets.Binding | ... | @@ -87,7 +89,8 @@ class Rivets.Binding |
87 | 89 | ||
88 | if @options.dependencies?.length | 90 | if @options.dependencies?.length |
89 | for keypath in @options.dependencies | 91 | for keypath in @options.dependencies |
90 | Rivets.config.adapter.unsubscribe @model, keypath, @reset | 92 | callback = @dependencyCallbacks[keypath] |
93 | Rivets.config.adapter.unsubscribe @model, keypath, callback | ||
91 | 94 | ||
92 | if @type in @bidirectionals | 95 | if @type in @bidirectionals |
93 | @el.removeEventListener 'change', @publish | 96 | @el.removeEventListener 'change', @publish | ... | ... |
-
Please register or sign in to post a comment