f1a9565d by Adam Heath

Abstract out the binder lookup code from the Binding constructor.

1 parent 6ad92e53
......@@ -9,13 +9,7 @@ Rivets = {}
# Polyfill For String::trim.
unless String::trim then String::trim = -> @replace /^\s+|\s+$/g, ''
# A single binding between a model attribute and a DOM element.
class Rivets.Binding
# All information about the binding is passed into the constructor; the DOM
# element, the type of binding, the model object and the keypath at which
# to listen for changes.
constructor: (@el, @type, @model, @keypath, options) ->
@options = (options ||= {})
findBinder = (type) ->
unless binder = Rivets.binders[type]
binder = Rivets.binders['*']
for identifier, value of Rivets.binders
......@@ -25,12 +19,21 @@ class Rivets.Binding
binder = value
args = regexp.exec type
args.shift()
@args = args
if binder instanceof Function
binder = {routine: binder}
@binder = binder
[binder, args]
# A single binding between a model attribute and a DOM element.
class Rivets.Binding
# All information about the binding is passed into the constructor; the DOM
# element, the type of binding, the model object and the keypath at which
# to listen for changes.
constructor: (@el, @type, @model, @keypath, options) ->
@options = (options ||= {})
[@binder, @args] = findBinder(type)
@formatters = options.formatters || []
# Applies all the current formatters to the supplied value and returns the
......