6e927599 by Michael Richards

Make sure that purposely "falsey" values can be set for a binding.

1 parent aea72d47
......@@ -23,28 +23,23 @@
Binding.prototype.set = function(value) {
var formatter, _i, _len, _ref;
if (value == null) {
value = null;
}
if (value || (value = Rivets.config.adapter.read(this.context, this.keypath))) {
_ref = this.formatters;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
formatter = _ref[_i];
value = Rivets.config.formatters[formatter](value);
}
return this.routine(this.el, value);
_ref = this.formatters;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
formatter = _ref[_i];
value = Rivets.config.formatters[formatter](value);
}
return this.routine(this.el, value);
};
Binding.prototype.bind = function() {
var _ref,
_this = this;
if (Rivets.config.preloadData) {
this.set();
}
Rivets.config.adapter.subscribe(this.context, this.keypath, function(value) {
return _this.set(value);
});
if (Rivets.config.preloadData) {
this.set(Rivets.config.adapter.read(this.context, this.keypath));
}
if (_ref = this.type, __indexOf.call(bidirectionals, _ref) >= 0) {
return this.el.addEventListener('change', function(e) {
var el;
......
......@@ -16,20 +16,21 @@ class Rivets.Binding
# Sets a value for this binding. Basically just runs the routine on the
# element with a suplied value and applies any formatters.
set: (value = null) =>
if value or= Rivets.config.adapter.read @context, @keypath
for formatter in @formatters
value = Rivets.config.formatters[formatter] value
set: (value) =>
for formatter in @formatters
value = Rivets.config.formatters[formatter] value
@routine @el, value
@routine @el, value
# Subscribes to the context object for changes on the specific keypath.
# Conditionally also does the inverse and listens to the element for changes
# to propogate back to the context object.
bind: =>
@set() if Rivets.config.preloadData
Rivets.config.adapter.subscribe @context, @keypath, (value) => @set value
if Rivets.config.preloadData
@set Rivets.config.adapter.read @context, @keypath
if @type in bidirectionals
@el.addEventListener 'change', (e) =>
el = e.target or e.srcElement
......