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 ...@@ -37,17 +37,17 @@ class Rivets.Binding
37 for formatter in @formatters 37 for formatter in @formatters
38 args = formatter.split /\s+/ 38 args = formatter.split /\s+/
39 id = args.shift() 39 id = args.shift()
40 value = if @model[id] instanceof Function 40
41 @model[id] value, args... 41 formatter = if @model[id] instanceof Function
42 else if Rivets.formatters[id] 42 @model[id]
43 if Rivets.formatters[id].read instanceof Function 43 else
44 Rivets.formatters[id].read value, args... 44 Rivets.formatters[id]
45 else if Rivets.formatters[id] instanceof Function # could occur if fmt = { publish: function() {}} 45
46 Rivets.formatters[id] value, args... 46 if formatter?.read instanceof Function
47 else # skip if no read function exists 47 value = formatter.read value, args...
48 value 48 else if formatter instanceof Function
49 else # skip if no formatter exists 49 value = formatter value, args...
50 value 50
51 value 51 value
52 52
53 # Sets the value for the binding. This Basically just runs the binding routine 53 # Sets the value for the binding. This Basically just runs the binding routine
...@@ -70,18 +70,15 @@ class Rivets.Binding ...@@ -70,18 +70,15 @@ class Rivets.Binding
70 # Publishes the value currently set on the input element back to the model. 70 # Publishes the value currently set on the input element back to the model.
71 publish: => 71 publish: =>
72 value = getInputValue @el 72 value = getInputValue @el
73 if @formatters 73
74 i = @formatters.length-1 74 for formatter in @formatters.slice(0).reverse()
75 while(i > -1) 75 args = formatter.split /\s+/
76 formatter = @formatters[i] 76 id = args.shift()
77 args = formatter.split /\s+/ 77
78 id = args.shift() 78 if Rivets.formatters[id]?.publish
79 # only re-assign if there is a two-way formatter. 79 value = Rivets.formatters[id].publish value, args...
80 if Rivets.formatters[id] and Rivets.formatters[id].publish 80
81 value = Rivets.formatters[id].publish value, args... 81 Rivets.config.adapter.publish @model, @keypath, value
82 i--
83 if(value)
84 Rivets.config.adapter.publish @model, @keypath, value
85 82
86 # Subscribes to the model for changes at the specified keypath. Bi-directional 83 # Subscribes to the model for changes at the specified keypath. Bi-directional
87 # routines will also listen for changes on the element to propagate them back 84 # routines will also listen for changes on the element to propagate them back
......