Merge pull request #98 from mikeric/allow-publishing-falsey-values
Allow publishing falsey values
Showing
1 changed file
with
16 additions
and
19 deletions
... | @@ -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,17 +70,14 @@ class Rivets.Binding | ... | @@ -70,17 +70,14 @@ 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) | ||
76 | formatter = @formatters[i] | ||
77 | args = formatter.split /\s+/ | 75 | args = formatter.split /\s+/ |
78 | id = args.shift() | 76 | id = args.shift() |
79 | # only re-assign if there is a two-way formatter. | 77 | |
80 | if Rivets.formatters[id] and Rivets.formatters[id].publish | 78 | if Rivets.formatters[id]?.publish |
81 | value = Rivets.formatters[id].publish value, args... | 79 | value = Rivets.formatters[id].publish value, args... |
82 | i-- | 80 | |
83 | if(value) | ||
84 | Rivets.config.adapter.publish @model, @keypath, value | 81 | 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 | ... | ... |
-
Please register or sign in to post a comment