26981461 by Michael Richards

Move the bidirectional binding check into it's own function.

1 parent 791a4bcc
...@@ -23,9 +23,11 @@ class Rivets.Binding ...@@ -23,9 +23,11 @@ class Rivets.Binding
23 23
24 @formatters = @options.formatters || [] 24 @formatters = @options.formatters || []
25 25
26 # Bindings that should also observe the DOM element for changes in order to 26 # Returns true|false depending on whether or not the binding should also
27 # propagate those changes back to the model object. 27 # observe the DOM element for changes in order to propagate those changes
28 bidirectionals: ['value', 'checked', 'unchecked'] 28 # back to the model object.
29 isBidirectional: =>
30 @type in ['value', 'checked', 'unchecked']
29 31
30 # Applies all the current formatters to the supplied value and returns the 32 # Applies all the current formatters to the supplied value and returns the
31 # formatted value. 33 # formatted value.
...@@ -77,7 +79,7 @@ class Rivets.Binding ...@@ -77,7 +79,7 @@ class Rivets.Binding
77 for keypath in @options.dependencies 79 for keypath in @options.dependencies
78 Rivets.config.adapter.subscribe @model, keypath, @sync 80 Rivets.config.adapter.subscribe @model, keypath, @sync
79 81
80 if @type in @bidirectionals 82 if @isBidirectional()
81 bindEvent @el, 'change', @publish 83 bindEvent @el, 'change', @publish
82 84
83 # Publishes the value currently set on the input element back to the model. 85 # Publishes the value currently set on the input element back to the model.
...@@ -94,7 +96,7 @@ class Rivets.Binding ...@@ -94,7 +96,7 @@ class Rivets.Binding
94 for keypath in @options.dependencies 96 for keypath in @options.dependencies
95 Rivets.config.adapter.unsubscribe @model, keypath, @sync 97 Rivets.config.adapter.unsubscribe @model, keypath, @sync
96 98
97 if @type in @bidirectionals 99 if @isBidirectional()
98 @el.removeEventListener 'change', @publish 100 @el.removeEventListener 'change', @publish
99 101
100 # A collection of bindings built from a set of parent elements. 102 # A collection of bindings built from a set of parent elements.
......