d6871d9c by Michael Richards

Build 0.3.0.

1 parent 0edcdf80
# Rivets.js
Rivets.js is a declarative data binding facility that plays well with existing frameworks such as [Backbone.js](http://backbonejs.org), [Spine.js](http://spinejs.com) and [Stapes.js](http://hay.github.com/stapes/). It aims to be lightweight (1.4KB minified and gzipped), extensible, and configurable to work with any event-driven model.
Rivets.js is a declarative data binding facility that plays well with existing frameworks such as [Backbone.js](http://backbonejs.org), [Spine.js](http://spinejs.com) and [Stapes.js](http://hay.github.com/stapes/). It aims to be lightweight (1.9KB minified and gzipped), extensible, and configurable to work with any event-driven model.
---
......
// rivets.js
// version: 0.2.7
// version: 0.3.0
// author: Michael Richards
// license: MIT
(function() {
......@@ -70,7 +70,8 @@
};
Binding.prototype.bind = function() {
var _ref;
var callback, keypath, _i, _len, _ref, _ref1, _ref2,
_this = this;
if (this.options.bypass) {
this.set(this.model[this.keypath]);
} else {
......@@ -79,7 +80,18 @@
this.set(Rivets.config.adapter.read(this.model, this.keypath));
}
}
if (_ref = this.type, __indexOf.call(this.bidirectionals, _ref) >= 0) {
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);
}
}
if (_ref2 = this.type, __indexOf.call(this.bidirectionals, _ref2) >= 0) {
return bindEvent(this.el, 'change', this.publish);
}
};
......@@ -91,9 +103,17 @@
};
Binding.prototype.unbind = function() {
var _ref;
var callback, keypath, _i, _len, _ref, _ref1, _ref2;
Rivets.config.adapter.unsubscribe(this.model, this.keypath, this.set);
if (_ref = this.type, __indexOf.call(this.bidirectionals, _ref) >= 0) {
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);
}
}
if (_ref2 = this.type, __indexOf.call(this.bidirectionals, _ref2) >= 0) {
return this.el.removeEventListener('change', this.publish);
}
};
......@@ -138,7 +158,7 @@
bindingRegExp = this.bindingRegExp();
eventRegExp = /^on-/;
parseNode = function(node) {
var attribute, keypath, model, options, path, pipe, pipes, type, _i, _len, _ref, _results;
var attribute, context, ctx, dependencies, keypath, model, options, path, pipe, pipes, type, _i, _len, _ref, _results;
_ref = node.attributes;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
......@@ -156,11 +176,24 @@
}
return _results1;
})();
path = pipes.shift().split(/(\.|:)/);
context = (function() {
var _j, _len1, _ref1, _results1;
_ref1 = pipes.shift().split('>');
_results1 = [];
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
ctx = _ref1[_j];
_results1.push(ctx.trim());
}
return _results1;
})();
path = context.shift().split(/(\.|:)/);
options.formatters = pipes;
model = _this.models[path.shift()];
options.bypass = path.shift() === ':';
keypath = path.join();
if (dependencies = context.shift()) {
options.dependencies = dependencies.split(/\s+/);
}
if (eventRegExp.test(type)) {
type = type.replace(eventRegExp, '');
options.special = "event";
......
{
"name" : "rivets",
"description" : "Declarative data binding facility.",
"version" : "0.2.7",
"version" : "0.3.0",
"author" : "Michael Richards",
"url" : "http://rivetsjs.com",
"main" : "./lib/rivets.js",
......
# rivets.js
# version : 0.2.7
# version : 0.3.0
# author : Michael Richards
# license : MIT
......