Make sure that purposely "falsey" values can be set for a binding.
Showing
2 changed files
with
15 additions
and
19 deletions
... | @@ -23,28 +23,23 @@ | ... | @@ -23,28 +23,23 @@ |
23 | 23 | ||
24 | Binding.prototype.set = function(value) { | 24 | Binding.prototype.set = function(value) { |
25 | var formatter, _i, _len, _ref; | 25 | var formatter, _i, _len, _ref; |
26 | if (value == null) { | 26 | _ref = this.formatters; |
27 | value = null; | 27 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
28 | } | 28 | formatter = _ref[_i]; |
29 | if (value || (value = Rivets.config.adapter.read(this.context, this.keypath))) { | 29 | value = Rivets.config.formatters[formatter](value); |
30 | _ref = this.formatters; | ||
31 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
32 | formatter = _ref[_i]; | ||
33 | value = Rivets.config.formatters[formatter](value); | ||
34 | } | ||
35 | return this.routine(this.el, value); | ||
36 | } | 30 | } |
31 | return this.routine(this.el, value); | ||
37 | }; | 32 | }; |
38 | 33 | ||
39 | Binding.prototype.bind = function() { | 34 | Binding.prototype.bind = function() { |
40 | var _ref, | 35 | var _ref, |
41 | _this = this; | 36 | _this = this; |
42 | if (Rivets.config.preloadData) { | ||
43 | this.set(); | ||
44 | } | ||
45 | Rivets.config.adapter.subscribe(this.context, this.keypath, function(value) { | 37 | Rivets.config.adapter.subscribe(this.context, this.keypath, function(value) { |
46 | return _this.set(value); | 38 | return _this.set(value); |
47 | }); | 39 | }); |
40 | if (Rivets.config.preloadData) { | ||
41 | this.set(Rivets.config.adapter.read(this.context, this.keypath)); | ||
42 | } | ||
48 | if (_ref = this.type, __indexOf.call(bidirectionals, _ref) >= 0) { | 43 | if (_ref = this.type, __indexOf.call(bidirectionals, _ref) >= 0) { |
49 | return this.el.addEventListener('change', function(e) { | 44 | return this.el.addEventListener('change', function(e) { |
50 | var el; | 45 | var el; | ... | ... |
... | @@ -16,20 +16,21 @@ class Rivets.Binding | ... | @@ -16,20 +16,21 @@ class Rivets.Binding |
16 | 16 | ||
17 | # Sets a value for this binding. Basically just runs the routine on the | 17 | # Sets a value for this binding. Basically just runs the routine on the |
18 | # element with a suplied value and applies any formatters. | 18 | # element with a suplied value and applies any formatters. |
19 | set: (value = null) => | 19 | set: (value) => |
20 | if value or= Rivets.config.adapter.read @context, @keypath | 20 | for formatter in @formatters |
21 | for formatter in @formatters | 21 | value = Rivets.config.formatters[formatter] value |
22 | value = Rivets.config.formatters[formatter] value | ||
23 | 22 | ||
24 | @routine @el, value | 23 | @routine @el, value |
25 | 24 | ||
26 | # Subscribes to the context object for changes on the specific keypath. | 25 | # Subscribes to the context object for changes on the specific keypath. |
27 | # Conditionally also does the inverse and listens to the element for changes | 26 | # Conditionally also does the inverse and listens to the element for changes |
28 | # to propogate back to the context object. | 27 | # to propogate back to the context object. |
29 | bind: => | 28 | bind: => |
30 | @set() if Rivets.config.preloadData | ||
31 | Rivets.config.adapter.subscribe @context, @keypath, (value) => @set value | 29 | Rivets.config.adapter.subscribe @context, @keypath, (value) => @set value |
32 | 30 | ||
31 | if Rivets.config.preloadData | ||
32 | @set Rivets.config.adapter.read @context, @keypath | ||
33 | |||
33 | if @type in bidirectionals | 34 | if @type in bidirectionals |
34 | @el.addEventListener 'change', (e) => | 35 | @el.addEventListener 'change', (e) => |
35 | el = e.target or e.srcElement | 36 | el = e.target or e.srcElement | ... | ... |
-
Please register or sign in to post a comment