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
@set Rivets.config.adapter.read @model, @keypath
if @options.dependencies?.length
@reset = (value) =>
@dependencyCallbacks = {}
for keypath in @options.dependencies
callback = @dependencyCallbacks[keypath] = (value) =>
@set if @options.bypass
@model[@keypath]
else
Rivets.config.adapter.read @model, @keypath
for keypath in @options.dependencies
Rivets.config.adapter.subscribe @model, keypath, @reset
Rivets.config.adapter.subscribe @model, keypath, callback
if @type in @bidirectionals
bindEvent @el, 'change', @publish
......@@ -87,7 +89,8 @@ class Rivets.Binding
if @options.dependencies?.length
for keypath in @options.dependencies
Rivets.config.adapter.unsubscribe @model, keypath, @reset
callback = @dependencyCallbacks[keypath]
Rivets.config.adapter.unsubscribe @model, keypath, callback
if @type in @bidirectionals
@el.removeEventListener 'change', @publish
......