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
# 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 = e.target or e.srcElement
Rivets.config.adapter.publish @model, @keypath, getInputValue el
@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
......@@ -144,4 +153,4 @@ rivets =
if module?
module.exports = rivets
else
@rivets = rivets
\ No newline at end of file
@rivets = rivets
......