f068c59b by Michael Richards

Merge pull request #15 from wrapp/feature/unsubsribing

Enable a way of unbinding listeners
2 parents 472cd08f 5b536cc6
...@@ -26,15 +26,24 @@ class Rivets.Binding ...@@ -26,15 +26,24 @@ 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 el = e.target or e.srcElement 36
37 Rivets.config.adapter.publish @model, @keypath, getInputValue el 37 publish: (e) =>
38 el = e.target or e.srcElement
39 Rivets.config.adapter.publish @model, @keypath, getInputValue el
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
38 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
...@@ -144,4 +153,4 @@ rivets = ...@@ -144,4 +153,4 @@ rivets =
144 if module? 153 if module?
145 module.exports = rivets 154 module.exports = rivets
146 else 155 else
147 @rivets = rivets
...\ No newline at end of file ...\ No newline at end of file
156 @rivets = rivets
......