Clean up the reverse formatter loop in publish and remove the value condition at…
… the end. [Closes #97]
Showing
1 changed file
with
9 additions
and
12 deletions
... | @@ -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 | ... | ... |
-
Please register or sign in to post a comment