ddef0dbd by Nicklas Ansman Giertz

Enable a way of unbinding listeners

1 parent 472cd08f
...@@ -26,16 +26,25 @@ class Rivets.Binding ...@@ -26,16 +26,25 @@ class Rivets.Binding
26 # routines will also listen for changes on the element to propagate them back 26 # routines will also listen for changes on the element to propagate them back
27 # to the model. 27 # to the model.
28 bind: => 28 bind: =>
29 Rivets.config.adapter.subscribe @model, @keypath, (value) => @set value 29 Rivets.config.adapter.subscribe @model, @keypath, @set
30 30
31 if Rivets.config.preloadData 31 if Rivets.config.preloadData
32 @set Rivets.config.adapter.read @model, @keypath 32 @set Rivets.config.adapter.read @model, @keypath
33 33
34 if @type in bidirectionals 34 if @type in bidirectionals
35 @el.addEventListener 'change', (e) => 35 @el.addEventListener('change', @publish)
36
37 publish: (e) =>
36 el = e.target or e.srcElement 38 el = e.target or e.srcElement
37 Rivets.config.adapter.publish @model, @keypath, getInputValue el 39 Rivets.config.adapter.publish @model, @keypath, getInputValue el
38 40
41 # Unsubscribes from the model and the element
42 unbind: =>
43 Rivets.config.adapter.unsubscribe @model, @keypath, @set
44
45 if @type in bidirectionals
46 @el.removeEventListener('change', @publish)
47
39 # A collection of bindings for a parent element. 48 # A collection of bindings for a parent element.
40 class Rivets.View 49 class Rivets.View
41 # The parent DOM element and the model objects for binding are passed into the 50 # The parent DOM element and the model objects for binding are passed into the
......