f068c59b by Michael Richards

Merge pull request #15 from wrapp/feature/unsubsribing

Enable a way of unbinding listeners
2 parents 472cd08f 5b536cc6
......@@ -26,16 +26,25 @@ class Rivets.Binding
# routines will also listen for changes on the element to propagate them back
# to the model.
bind: =>
Rivets.config.adapter.subscribe @model, @keypath, (value) => @set value
Rivets.config.adapter.subscribe @model, @keypath, @set
if Rivets.config.preloadData
@set Rivets.config.adapter.read @model, @keypath
if @type in bidirectionals
@el.addEventListener 'change', (e) =>
@el.addEventListener 'change', @publish
publish: (e) =>
el = e.target or e.srcElement
Rivets.config.adapter.publish @model, @keypath, getInputValue el
# Unsubscribes from the model and the element
unbind: =>
Rivets.config.adapter.unsubscribe @model, @keypath, @set
if @type in bidirectionals
@el.removeEventListener 'change', @publish
# A collection of bindings for a parent element.
class Rivets.View
# The parent DOM element and the model objects for binding are passed into the
......