19d6db6b by Michael Richards

Merge pull request #98 from mikeric/allow-publishing-falsey-values

Allow publishing falsey values
2 parents 924b7ba1 51018f8d
......@@ -37,17 +37,17 @@ class Rivets.Binding
for formatter in @formatters
args = formatter.split /\s+/
id = args.shift()
value = if @model[id] instanceof Function
@model[id] value, args...
else if Rivets.formatters[id]
if Rivets.formatters[id].read instanceof Function
Rivets.formatters[id].read value, args...
else if Rivets.formatters[id] instanceof Function # could occur if fmt = { publish: function() {}}
Rivets.formatters[id] value, args...
else # skip if no read function exists
value
else # skip if no formatter exists
value
formatter = if @model[id] instanceof Function
@model[id]
else
Rivets.formatters[id]
if formatter?.read instanceof Function
value = formatter.read value, args...
else if formatter instanceof Function
value = formatter value, args...
value
# Sets the value for the binding. This Basically just runs the binding routine
......@@ -70,17 +70,14 @@ class Rivets.Binding
# Publishes the value currently set on the input element back to the model.
publish: =>
value = getInputValue @el
if @formatters
i = @formatters.length-1
while(i > -1)
formatter = @formatters[i]
for formatter in @formatters.slice(0).reverse()
args = formatter.split /\s+/
id = args.shift()
# only re-assign if there is a two-way formatter.
if Rivets.formatters[id] and Rivets.formatters[id].publish
if Rivets.formatters[id]?.publish
value = Rivets.formatters[id].publish value, args...
i--
if(value)
Rivets.config.adapter.publish @model, @keypath, value
# Subscribes to the model for changes at the specified keypath. Bi-directional
......