92c7149d by Michael Richards

Implement a separate callback space so that setting callback.wrapped in adapter.…

…subscribe won't overwrite the existing wrapped function, making the binding unbindable.
1 parent 8ba303c7
...@@ -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 @set if @options.bypass 68
69 @model[@keypath]
70 else
71 Rivets.config.adapter.read @model, @keypath
72
73 for keypath in @options.dependencies 69 for keypath in @options.dependencies
74 Rivets.config.adapter.subscribe @model, keypath, @reset 70 callback = @dependencyCallbacks[keypath] = (value) =>
71 @set if @options.bypass
72 @model[@keypath]
73 else
74 Rivets.config.adapter.read @model, @keypath
75
76 Rivets.config.adapter.subscribe @model, keypath, callback
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
......