1e6b3edf by Michael Richards

Build 0.3.6.

1 parent 078497e0
// rivets.js
// version: 0.3.5
// version: 0.3.6
// author: Michael Richards
// license: MIT
(function() {
......@@ -26,14 +26,18 @@
this.options = options != null ? options : {};
this.unbind = __bind(this.unbind, this);
this.bind = __bind(this.bind, this);
this.publish = __bind(this.publish, this);
this.bind = __bind(this.bind, this);
this.sync = __bind(this.sync, this);
this.set = __bind(this.set, this);
this.formattedValue = __bind(this.formattedValue, this);
this.isBidirectional = __bind(this.isBidirectional, this);
this.routine = (function() {
switch (this.options.special) {
case "event":
......@@ -49,7 +53,10 @@
this.formatters = this.options.formatters || [];
}
Binding.prototype.bidirectionals = ['value', 'checked', 'unchecked'];
Binding.prototype.isBidirectional = function() {
var _ref;
return (_ref = this.type) === 'value' || _ref === 'checked' || _ref === 'unchecked';
};
Binding.prototype.formattedValue = function(value) {
var args, formatter, id, _i, _len, _ref, _ref1, _ref2;
......@@ -75,52 +82,48 @@
}
};
Binding.prototype.sync = function() {
return this.set(this.options.bypass ? this.model[this.keypath] : Rivets.config.adapter.read(this.model, this.keypath));
};
Binding.prototype.publish = function() {
return Rivets.config.adapter.publish(this.model, this.keypath, getInputValue(this.el));
};
Binding.prototype.bind = function() {
var callback, keypath, _i, _len, _ref, _ref1, _ref2,
_this = this;
var keypath, _i, _len, _ref, _ref1;
if (this.options.bypass) {
this.set(this.model[this.keypath]);
this.sync();
} else {
Rivets.config.adapter.subscribe(this.model, this.keypath, this.set);
Rivets.config.adapter.subscribe(this.model, this.keypath, this.sync);
if (Rivets.config.preloadData) {
this.set(Rivets.config.adapter.read(this.model, this.keypath));
this.sync();
}
}
if ((_ref = this.options.dependencies) != null ? _ref.length : void 0) {
this.dependencyCallbacks = {};
_ref1 = this.options.dependencies;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
keypath = _ref1[_i];
callback = this.dependencyCallbacks[keypath] = function(value) {
return _this.set(_this.options.bypass ? _this.model[_this.keypath] : Rivets.config.adapter.read(_this.model, _this.keypath));
};
Rivets.config.adapter.subscribe(this.model, keypath, callback);
Rivets.config.adapter.subscribe(this.model, keypath, this.sync);
}
}
if (_ref2 = this.type, __indexOf.call(this.bidirectionals, _ref2) >= 0) {
if (this.isBidirectional()) {
return bindEvent(this.el, 'change', this.publish);
}
};
Binding.prototype.publish = function(e) {
var el;
el = e.target || e.srcElement;
return Rivets.config.adapter.publish(this.model, this.keypath, getInputValue(el));
};
Binding.prototype.unbind = function() {
var callback, keypath, _i, _len, _ref, _ref1, _ref2;
var keypath, _i, _len, _ref, _ref1;
if (!this.options.bypass) {
Rivets.config.adapter.unsubscribe(this.model, this.keypath, this.set);
Rivets.config.adapter.unsubscribe(this.model, this.keypath, this.sync);
if ((_ref = this.options.dependencies) != null ? _ref.length : void 0) {
_ref1 = this.options.dependencies;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
keypath = _ref1[_i];
callback = this.dependencyCallbacks[keypath];
Rivets.config.adapter.unsubscribe(this.model, keypath, callback);
Rivets.config.adapter.unsubscribe(this.model, keypath, this.sync);
}
}
if (_ref2 = this.type, __indexOf.call(this.bidirectionals, _ref2) >= 0) {
if (this.isBidirectional()) {
return this.el.removeEventListener('change', this.publish);
}
}
......@@ -135,10 +138,16 @@
function View(els, models) {
this.els = els;
this.models = models;
this.publish = __bind(this.publish, this);
this.sync = __bind(this.sync, this);
this.unbind = __bind(this.unbind, this);
this.bind = __bind(this.bind, this);
this.select = __bind(this.select, this);
this.build = __bind(this.build, this);
this.bindingRegExp = __bind(this.bindingRegExp, this);
......@@ -264,6 +273,19 @@
}
};
View.prototype.select = function(fn) {
var binding, _i, _len, _ref, _results;
_ref = this.bindings;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
binding = _ref[_i];
if (fn(binding)) {
_results.push(binding);
}
}
return _results;
};
View.prototype.bind = function() {
var binding, _i, _len, _ref, _results;
_ref = this.bindings;
......@@ -286,6 +308,30 @@
return _results;
};
View.prototype.sync = function() {
var binding, _i, _len, _ref, _results;
_ref = this.bindings;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
binding = _ref[_i];
_results.push(binding.sync());
}
return _results;
};
View.prototype.publish = function() {
var binding, _i, _len, _ref, _results;
_ref = this.select(function(b) {
return b.isBidirectional();
});
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
binding = _ref[_i];
_results.push(binding.publish());
}
return _results;
};
return View;
})();
......
{
"name" : "rivets",
"description" : "Declarative data binding facility.",
"version" : "0.3.5",
"version" : "0.3.6",
"author" : "Michael Richards",
"url" : "http://rivetsjs.com",
"main" : "./lib/rivets.js",
......
# rivets.js
# version : 0.3.5
# version : 0.3.6
# author : Michael Richards
# license : MIT
......