Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

bump version, build distribution

  • Loading branch information...
commit f65c95fdc493c19f0fefdce0c8bb8b06b7b74ba1 1 parent 47b6d3f
@hunterloftis authored
View
7 Makefile
@@ -1,12 +1,15 @@
-VERSION=0.1.0
+VERSION=0.2.0
IN=dist/backbone.viewmodel-$(VERSION).js
OUT=dist/backbone.viewmodel-$(VERSION).min.js
+full: dist
+ open test/test_prod.html
+
dist: js
echo "Development: $(IN)"
echo "Production: $(OUT)"
- cat backbone.viewmodel.js backbone.virtual.js backbone.binding.js lib/bindings.js > $(IN)
+ cat lib/backbone.viewmodel.js lib/backbone.viewcollection.js lib/backbone.virtual.js lib/backbone.binding.js lib/bindings.js > $(IN)
curl -s \
-d compilation_level=SIMPLE_OPTIMIZATIONS \
View
646 dist/backbone.viewmodel-0.2.0.js
@@ -0,0 +1,646 @@
+// Generated by CoffeeScript 1.3.3
+(function() {
+ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
+ __hasProp = {}.hasOwnProperty,
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
+
+ (function(Backbone) {
+ var argMap, proto;
+ proto = Backbone.Model.prototype;
+ argMap = {
+ 'undefined': void 0,
+ 'null': null,
+ 'true': true,
+ 'false': false
+ };
+ Backbone.ViewModel = (function(_super) {
+
+ __extends(ViewModel, _super);
+
+ function ViewModel(attributes, options) {
+ this.onVirtual = __bind(this.onVirtual, this);
+
+ this.createVirtual = __bind(this.createVirtual, this);
+
+ this.parseBinding = __bind(this.parseBinding, this);
+
+ this.bindToNode = __bind(this.bindToNode, this);
+ this._virtuals = {};
+ this._bindings = [];
+ ViewModel.__super__.constructor.apply(this, arguments);
+ }
+
+ ViewModel.prototype.set = function(key, value, options) {
+ var virtual, _ref;
+ if (!(options && options.dependency)) {
+ virtual = ((_ref = this._virtuals) != null ? _ref.hasOwnProperty(key) : void 0) && this._virtuals[key];
+ if (virtual) {
+ return virtual.set.call(this, key, value, options, virtual);
+ }
+ }
+ return proto.set.apply(this, arguments);
+ };
+
+ ViewModel.prototype.bindView = function(attribute, container) {
+ var node, nodes, selector, _i, _len;
+ if (container == null) {
+ container = 'body';
+ }
+ selector = '*[' + attribute + ']';
+ nodes = $(container).find(selector);
+ if ($(container).is(selector)) {
+ nodes = $(container).add(nodes);
+ }
+ for (_i = 0, _len = nodes.length; _i < _len; _i++) {
+ node = nodes[_i];
+ this.bindToNode(attribute, node);
+ }
+ return nodes;
+ };
+
+ ViewModel.prototype.unbindView = function() {
+ var binding, _i, _len, _ref;
+ _ref = this._bindings;
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ binding = _ref[_i];
+ binding.stop();
+ }
+ return this._bindings = [];
+ };
+
+ ViewModel.prototype.isBoundTo = function(node) {
+ var binding, _i, _len, _ref;
+ _ref = this._bindings;
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ binding = _ref[_i];
+ if (binding.node === node) {
+ return true;
+ }
+ }
+ return false;
+ };
+
+ ViewModel.prototype.bindToNode = function(attribute, node) {
+ var bindingList, bindingString, description, descriptions, pair, _i, _len, _results;
+ if (this.isBoundTo(node)) {
+ return;
+ }
+ bindingString = $(node).attr(attribute);
+ bindingList = bindingString.split(';');
+ descriptions = (function() {
+ var _i, _len, _results;
+ _results = [];
+ for (_i = 0, _len = bindingList.length; _i < _len; _i++) {
+ pair = bindingList[_i];
+ _results.push(this.parseBinding(node, attribute, pair));
+ }
+ return _results;
+ }).call(this);
+ _results = [];
+ for (_i = 0, _len = descriptions.length; _i < _len; _i++) {
+ description = descriptions[_i];
+ _results.push(this.createBinding(description));
+ }
+ return _results;
+ };
+
+ ViewModel.prototype.parseBinding = function(node, attribute, pair) {
+ var arg, argString, args, type, typeSplit;
+ typeSplit = pair.split('(');
+ type = typeSplit[0].trim();
+ argString = typeSplit[1].trim().slice(0, -1);
+ args = (function() {
+ var _i, _len, _ref, _results;
+ _ref = argString.split(',');
+ _results = [];
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ arg = _ref[_i];
+ _results.push(this.parseArgument(arg));
+ }
+ return _results;
+ }).call(this);
+ return {
+ node: node,
+ viewModel: this,
+ type: type,
+ bindingAttr: attribute,
+ args: args
+ };
+ };
+
+ ViewModel.prototype.parseArgument = function(arg) {
+ arg = arg.trim();
+ if (argMap.hasOwnProperty(arg)) {
+ arg = argMap[arg];
+ } else if (!isNaN(arg)) {
+ arg = Number(arg);
+ }
+ return arg;
+ };
+
+ ViewModel.prototype.createBinding = function(description) {
+ var Binding, binding;
+ Binding = Backbone.Binding[description.type];
+ if (Binding != null) {
+ binding = new Binding(description);
+ binding.start();
+ this._bindings.push(binding);
+ return binding;
+ } else {
+ throw new Error('Trying to create a binding of unknown type "' + description.type + '"');
+ }
+ };
+
+ ViewModel.prototype.get = function(attr) {
+ Backbone.Virtual.track(this, 'change:' + attr);
+ return this.attributes[attr];
+ };
+
+ ViewModel.prototype.compute = function() {
+ var args, get;
+ args = _.toArray(arguments);
+ get = args.pop();
+ args.push({
+ get: get
+ });
+ return this.virtual.apply(this, args);
+ };
+
+ ViewModel.prototype.pass = function() {
+ var args, reference;
+ args = _.toArray(arguments);
+ reference = args.pop();
+ args.push({
+ reference: reference
+ });
+ return this.virtual.apply(this, args);
+ };
+
+ ViewModel.prototype.virtual = function() {
+ var attr, attrs, options;
+ attrs = _.toArray(arguments);
+ options = attrs.pop();
+ options.model = this;
+ return (function() {
+ var _i, _len, _results;
+ _results = [];
+ for (_i = 0, _len = attrs.length; _i < _len; _i++) {
+ attr = attrs[_i];
+ _results.push(this.createVirtual(attr, options));
+ }
+ return _results;
+ }).call(this);
+ };
+
+ ViewModel.prototype.createVirtual = function(attr, options) {
+ var newVirtual, opts;
+ opts = _.extend({}, options, {
+ attr: attr
+ });
+ newVirtual = new Backbone.Virtual(opts);
+ this._virtuals[attr] = newVirtual;
+ newVirtual.on('change', this.onVirtual);
+ return newVirtual.run();
+ };
+
+ ViewModel.prototype.onVirtual = function(virtual) {
+ return this.set(virtual.attr, virtual.result, {
+ dependency: true
+ });
+ };
+
+ return ViewModel;
+
+ })(Backbone.Model);
+ return Backbone.Model = Backbone.ViewModel;
+ })(Backbone);
+
+}).call(this);
+// Generated by CoffeeScript 1.3.3
+(function() {
+ var __hasProp = {}.hasOwnProperty,
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
+
+ (function(Backbone) {
+ var backboneReads, extendCollection, fn, proto, underscoreReads, writes, _i, _len, _ref;
+ proto = Backbone.Collection.prototype;
+ writes = 'add remove reset change create sort';
+ backboneReads = ['get', 'getByCid', 'where', 'pluck', 'clone', 'at', 'toJSON'];
+ underscoreReads = ['forEach', 'each', 'map', 'reduce', 'reduceRight', 'find', 'detect', 'filter', 'select', 'reject', 'every', 'all', 'some', 'any', 'include', 'contains', 'invoke', 'max', 'min', 'sortBy', 'sortedIndex', 'toArray', 'size', 'first', 'initial', 'rest', 'last', 'without', 'indexOf', 'shuffle', 'lastIndexOf', 'isEmpty', 'groupBy'];
+ Backbone.ViewCollection = (function(_super) {
+
+ __extends(ViewCollection, _super);
+
+ function ViewCollection() {
+ return ViewCollection.__super__.constructor.apply(this, arguments);
+ }
+
+ ViewCollection.prototype.list = function() {
+ Backbone.Virtual.track(this, writes);
+ return this.models;
+ };
+
+ return ViewCollection;
+
+ })(Backbone.Collection);
+ Backbone.Collection.prototype.model = Backbone.Model;
+ extendCollection = function(name) {
+ return Backbone.ViewCollection.prototype[name] = function() {
+ Backbone.Virtual.track(this, writes);
+ return proto[name].apply(this, arguments);
+ };
+ };
+ _ref = backboneReads.concat(underscoreReads);
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ fn = _ref[_i];
+ extendCollection(fn);
+ }
+ return Backbone.Collection = Backbone.ViewCollection;
+ })(Backbone);
+
+}).call(this);
+// Generated by CoffeeScript 1.3.3
+(function() {
+ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
+
+ (function(Backbone) {
+ Backbone.Virtual = (function() {
+
+ Virtual._computations = [];
+
+ Virtual._dependencies = void 0;
+
+ Virtual.startTracking = function() {
+ Backbone.Virtual._dependencies = [];
+ return Backbone.Virtual._computations.push(Backbone.Virtual._dependencies);
+ };
+
+ Virtual.stopTracking = function() {
+ var computations, dependencies;
+ computations = Backbone.Virtual._computations;
+ dependencies = computations.pop();
+ if (computations.length) {
+ Backbone.Virtual._dependencies = computations[computations.length - 1];
+ } else {
+ Backbone.Virtual._dependencies = void 0;
+ }
+ return dependencies;
+ };
+
+ Virtual.track = function(model, event) {
+ var _ref;
+ return (_ref = Backbone.Virtual._dependencies) != null ? _ref.push({
+ model: model,
+ event: event
+ }) : void 0;
+ };
+
+ function Virtual(options) {
+ this.remove = __bind(this.remove, this);
+
+ this.add = __bind(this.add, this);
+
+ this.update = __bind(this.update, this);
+
+ this.onChange = __bind(this.onChange, this);
+
+ this.run = __bind(this.run, this);
+
+ this.runSafe = __bind(this.runSafe, this);
+ _.extend(this, options);
+ this.dependencies = [];
+ this.result = void 0;
+ }
+
+ Virtual.prototype.runSafe = function() {
+ try {
+ return this.get.call(this.model, this.attr, this);
+ } catch (error) {
+ return this.fail;
+ }
+ };
+
+ Virtual.prototype.run = function() {
+ Backbone.Virtual.startTracking();
+ if (this.hasOwnProperty('fail')) {
+ this.result = this.runSafe();
+ } else {
+ this.result = this.get.call(this.model, this.attr, this);
+ }
+ this.update(Backbone.Virtual.stopTracking());
+ this.trigger('change', this);
+ return this.result;
+ };
+
+ Virtual.prototype.onChange = function() {
+ return this.run();
+ };
+
+ Virtual.prototype.update = function(newDependencies) {
+ var dep, _i, _j, _len, _len1, _ref;
+ _ref = this.dependencies;
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ dep = _ref[_i];
+ this.remove(dep);
+ }
+ for (_j = 0, _len1 = newDependencies.length; _j < _len1; _j++) {
+ dep = newDependencies[_j];
+ this.add(dep);
+ }
+ return this.dependencies = newDependencies;
+ };
+
+ Virtual.prototype.add = function(dependency) {
+ return dependency.model.on(dependency.event, this.onChange);
+ };
+
+ Virtual.prototype.remove = function(dependency) {
+ return dependency.model.off(dependency.event, this.onChange);
+ };
+
+ Virtual.prototype.get = function(attr, virtual) {
+ var model;
+ if (typeof virtual.reference === 'function') {
+ model = virtual.reference.call(this);
+ } else {
+ model = virtual.reference;
+ }
+ return model.get(attr);
+ };
+
+ Virtual.prototype.set = function(attr, val, options, virtual) {
+ var model;
+ if (typeof virtual.reference === 'function') {
+ model = virtual.reference.call(this);
+ } else {
+ model = virtual.reference;
+ }
+ return model.set(attr, val);
+ };
+
+ return Virtual;
+
+ })();
+ return _.extend(Backbone.Virtual.prototype, Backbone.Events);
+ })(Backbone);
+
+}).call(this);
+// Generated by CoffeeScript 1.3.3
+(function() {
+ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
+
+ (function(Backbone) {
+ Backbone.Binding = (function() {
+
+ function Binding(description) {
+ this.stop = __bind(this.stop, this);
+
+ this.start = __bind(this.start, this);
+
+ this.onViewChange = __bind(this.onViewChange, this);
+
+ this.onCollectionChange = __bind(this.onCollectionChange, this);
+
+ this.onModelChange = __bind(this.onModelChange, this);
+
+ this.initialize = __bind(this.initialize, this);
+ _.extend(this, description);
+ this.initialize.apply(this, description.args);
+ }
+
+ Binding.prototype.initialize = function() {};
+
+ Binding.prototype.onModelChange = function() {};
+
+ Binding.prototype.onCollectionChange = function() {};
+
+ Binding.prototype.onViewChange = function() {};
+
+ Binding.prototype.start = function() {
+ this.viewModel.on('change:' + this.attribute, this.onModelChange);
+ return this.onModelChange();
+ };
+
+ Binding.prototype.stop = function() {
+ return this.viewModel.off('change:' + this.attribute, this.onModelChange);
+ };
+
+ return Binding;
+
+ })();
+ return Backbone.Binding.extend = Backbone.Model.extend;
+ })(Backbone);
+
+}).call(this);
+// Generated by CoffeeScript 1.3.3
+(function() {
+ var __hasProp = {}.hasOwnProperty,
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
+ __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
+
+ (function(Backbone) {
+ var ClickBinding, CssBinding, EachBinding, TextBinding, ValueBinding, VisibleBinding;
+ Backbone.Binding['visible'] = VisibleBinding = (function(_super) {
+
+ __extends(VisibleBinding, _super);
+
+ function VisibleBinding() {
+ return VisibleBinding.__super__.constructor.apply(this, arguments);
+ }
+
+ VisibleBinding.prototype.initialize = function(attribute) {
+ this.attribute = attribute;
+ };
+
+ VisibleBinding.prototype.onModelChange = function() {
+ var val;
+ val = this.viewModel.get(this.attribute);
+ if (val) {
+ return $(this.node).show();
+ }
+ return $(this.node).hide();
+ };
+
+ return VisibleBinding;
+
+ })(Backbone.Binding);
+ Backbone.Binding['text'] = TextBinding = (function(_super) {
+
+ __extends(TextBinding, _super);
+
+ function TextBinding() {
+ return TextBinding.__super__.constructor.apply(this, arguments);
+ }
+
+ TextBinding.prototype.initialize = function(attribute) {
+ this.attribute = attribute;
+ };
+
+ TextBinding.prototype.onModelChange = function() {
+ var val;
+ val = this.viewModel.get(this.attribute);
+ return $(this.node).text(val);
+ };
+
+ return TextBinding;
+
+ })(Backbone.Binding);
+ Backbone.Binding['val'] = ValueBinding = (function(_super) {
+
+ __extends(ValueBinding, _super);
+
+ function ValueBinding() {
+ return ValueBinding.__super__.constructor.apply(this, arguments);
+ }
+
+ ValueBinding.prototype.initialize = function(attribute) {
+ this.attribute = attribute;
+ };
+
+ ValueBinding.prototype.start = function() {
+ ValueBinding.__super__.start.apply(this, arguments);
+ return $(this.node).on('keyup change', this.onViewChange);
+ };
+
+ ValueBinding.prototype.onModelChange = function() {
+ var val;
+ val = this.viewModel.get(this.attribute);
+ return $(this.node).val(val);
+ };
+
+ ValueBinding.prototype.onViewChange = function() {
+ var val;
+ val = $(this.node).val();
+ return this.viewModel.set(this.attribute, val);
+ };
+
+ ValueBinding.prototype.stop = function() {
+ ValueBinding.__super__.stop.apply(this, arguments);
+ return $(this.node).off('keyup change', this.onViewChange);
+ };
+
+ return ValueBinding;
+
+ })(Backbone.Binding);
+ Backbone.Binding['css'] = CssBinding = (function(_super) {
+
+ __extends(CssBinding, _super);
+
+ function CssBinding() {
+ return CssBinding.__super__.constructor.apply(this, arguments);
+ }
+
+ CssBinding.prototype.initialize = function(className, attribute, truth) {
+ this.className = className;
+ this.attribute = attribute;
+ this.truth = truth != null ? truth : true;
+ };
+
+ CssBinding.prototype.onModelChange = function() {
+ var val;
+ val = this.viewModel.get(this.attribute);
+ if (Boolean(this.truth) === Boolean(val)) {
+ return $(this.node).addClass(this.className);
+ }
+ return $(this.node).removeClass(this.className);
+ };
+
+ return CssBinding;
+
+ })(Backbone.Binding);
+ Backbone.Binding['click'] = ClickBinding = (function(_super) {
+
+ __extends(ClickBinding, _super);
+
+ function ClickBinding() {
+ return ClickBinding.__super__.constructor.apply(this, arguments);
+ }
+
+ ClickBinding.prototype.initialize = function() {
+ var args;
+ args = _.toArray(arguments);
+ this.callback = args.shift();
+ return this.args = args;
+ };
+
+ ClickBinding.prototype.start = function() {
+ return $(this.node).on('click', this.onViewChange);
+ };
+
+ ClickBinding.prototype.onViewChange = function(event) {
+ var callback, _ref;
+ event.preventDefault();
+ callback = (_ref = this.viewModel[this.callback]) != null ? _ref : this.viewModel.get(this.callback);
+ return callback.apply(this.viewModel, this.args);
+ };
+
+ ClickBinding.prototype.stop = function() {
+ return $(this.node).off('click', this.onViewChange);
+ };
+
+ return ClickBinding;
+
+ })(Backbone.Binding);
+ return Backbone.Binding['each'] = EachBinding = (function(_super) {
+
+ __extends(EachBinding, _super);
+
+ function EachBinding() {
+ this.renderItem = __bind(this.renderItem, this);
+ return EachBinding.__super__.constructor.apply(this, arguments);
+ }
+
+ EachBinding.prototype.initialize = function(attr) {
+ this.attr = attr;
+ this.container = $(this.node);
+ this.itemTemplate = this.container.html();
+ return this.container.html('');
+ };
+
+ EachBinding.prototype.start = function() {
+ this.viewModel.on('change:' + this.attr, this.onCollectionChange);
+ return this.onCollectionChange();
+ };
+
+ EachBinding.prototype.onCollectionChange = function() {
+ var item, self, _i, _len, _ref, _results;
+ self = this;
+ this.container.html('');
+ this.collection = this.viewModel.get(this.attr);
+ if (this.collection instanceof Backbone.Collection) {
+ this.collection.off('add remove reset change create sort', this.onCollectionChange);
+ this.collection.each(this.renderItem);
+ return this.collection.on('add remove reset change create sort', this.onCollectionChange);
+ } else {
+ _ref = this.collection;
+ _results = [];
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ item = _ref[_i];
+ _results.push(this.renderItem(item));
+ }
+ return _results;
+ }
+ };
+
+ EachBinding.prototype.renderItem = function(viewModel) {
+ var node, _i, _len, _ref, _results;
+ _ref = $(this.itemTemplate);
+ _results = [];
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ node = _ref[_i];
+ this.container.append(node);
+ _results.push(viewModel.bindView(this.bindingAttr, node));
+ }
+ return _results;
+ };
+
+ EachBinding.prototype.stop = function() {
+ return this.viewModel.off('change:' + this.attr, this.onCollectionChange);
+ };
+
+ return EachBinding;
+
+ })(Backbone.Binding);
+ })(Backbone);
+
+}).call(this);
View
23 dist/backbone.viewmodel-0.2.0.min.js
@@ -0,0 +1,23 @@
+(function(){var h=function(b,c){return function(){return b.apply(c,arguments)}},f={}.hasOwnProperty,d=function(b,c){function a(){this.constructor=b}for(var e in c)f.call(c,e)&&(b[e]=c[e]);a.prototype=c.prototype;b.prototype=new a;b.__super__=c.prototype;return b};(function(b){var c,a;a=b.Model.prototype;c={undefined:void 0,"null":null,"true":!0,"false":!1};b.ViewModel=function(e){function g(b,a){this.onVirtual=h(this.onVirtual,this);this.createVirtual=h(this.createVirtual,this);this.parseBinding=
+h(this.parseBinding,this);this.bindToNode=h(this.bindToNode,this);this._virtuals={};this._bindings=[];g.__super__.constructor.apply(this,arguments)}d(g,e);g.prototype.set=function(b,c,e){var d,g;if(!e||!e.dependency)if(d=(null!=(g=this._virtuals)?g.hasOwnProperty(b):void 0)&&this._virtuals[b])return d.set.call(this,b,c,e,d);return a.set.apply(this,arguments)};g.prototype.bindView=function(b,a){var e,c,d,g;null==a&&(a="body");e="*["+b+"]";c=$(a).find(e);$(a).is(e)&&(c=$(a).add(c));d=0;for(g=c.length;d<
+g;d++)e=c[d],this.bindToNode(b,e);return c};g.prototype.unbindView=function(){var b,a,e,c;c=this._bindings;a=0;for(e=c.length;a<e;a++)b=c[a],b.stop();return this._bindings=[]};g.prototype.isBoundTo=function(b){var a,c,e,d;d=this._bindings;c=0;for(e=d.length;c<e;c++)if(a=d[c],a.node===b)return!0;return!1};g.prototype.bindToNode=function(a,b){var c,e,d,g,f;if(!this.isBoundTo(b)){e=$(b).attr(a);c=e.split(";");e=[];g=0;for(f=c.length;g<f;g++)d=c[g],e.push(this.parseBinding(b,a,d));f=[];d=0;for(g=e.length;d<
+g;d++)c=e[d],f.push(this.createBinding(c));return f}};g.prototype.parseBinding=function(b,a,c){var e;e=c.split("(");var c=e[0].trim(),d,g,f,h;f=e[1].trim().slice(0,-1).split(",");h=[];d=0;for(g=f.length;d<g;d++)e=f[d],h.push(this.parseArgument(e));return{node:b,viewModel:this,type:c,bindingAttr:a,args:h}};g.prototype.parseArgument=function(b){b=b.trim();c.hasOwnProperty(b)?b=c[b]:isNaN(b)||(b=Number(b));return b};g.prototype.createBinding=function(a){var e;e=b.Binding[a.type];if(null!=e)return a=
+new e(a),a.start(),this._bindings.push(a),a;throw Error('Trying to create a binding of unknown type "'+a.type+'"');};g.prototype.get=function(a){b.Virtual.track(this,"change:"+a);return this.attributes[a]};g.prototype.compute=function(){var a,b;a=_.toArray(arguments);b=a.pop();a.push({get:b});return this.virtual.apply(this,a)};g.prototype.pass=function(){var a,b;a=_.toArray(arguments);b=a.pop();a.push({reference:b});return this.virtual.apply(this,a)};g.prototype.virtual=function(){var a,b,e;b=_.toArray(arguments);
+e=b.pop();e.model=this;var c,d,g;g=[];c=0;for(d=b.length;c<d;c++)a=b[c],g.push(this.createVirtual(a,e));return g};g.prototype.createVirtual=function(a,e){var c;c=_.extend({},e,{attr:a});c=new b.Virtual(c);this._virtuals[a]=c;c.on("change",this.onVirtual);return c.run()};g.prototype.onVirtual=function(a){return this.set(a.attr,a.result,{dependency:!0})};return g}(b.Model);return b.Model=b.ViewModel})(Backbone)}).call(this);
+(function(){var h={}.hasOwnProperty,f=function(d,b){function c(){this.constructor=d}for(var a in b)h.call(b,a)&&(d[a]=b[a]);c.prototype=b.prototype;d.prototype=new c;d.__super__=b.prototype;return d};(function(d){var b,c,a,e,g,h;a=d.Collection.prototype;d.ViewCollection=function(a){function b(){return b.__super__.constructor.apply(this,arguments)}f(b,a);b.prototype.list=function(){d.Virtual.track(this,"add remove reset change create sort");return this.models};return b}(d.Collection);d.Collection.prototype.model=
+d.Model;b=function(b){return d.ViewCollection.prototype[b]=function(){d.Virtual.track(this,"add remove reset change create sort");return a[b].apply(this,arguments)}};h="get getByCid where pluck clone at toJSON".split(" ").concat("forEach each map reduce reduceRight find detect filter select reject every all some any include contains invoke max min sortBy sortedIndex toArray size first initial rest last without indexOf shuffle lastIndexOf isEmpty groupBy".split(" "));e=0;for(g=h.length;e<g;e++)c=h[e],
+b(c);return d.Collection=d.ViewCollection})(Backbone)}).call(this);
+(function(){var h=function(f,d){return function(){return f.apply(d,arguments)}};(function(f){f.Virtual=function(){function d(b){this.remove=h(this.remove,this);this.add=h(this.add,this);this.update=h(this.update,this);this.onChange=h(this.onChange,this);this.run=h(this.run,this);this.runSafe=h(this.runSafe,this);_.extend(this,b);this.dependencies=[];this.result=void 0}d._computations=[];d._dependencies=void 0;d.startTracking=function(){f.Virtual._dependencies=[];return f.Virtual._computations.push(f.Virtual._dependencies)};
+d.stopTracking=function(){var b,c;b=f.Virtual._computations;c=b.pop();f.Virtual._dependencies=b.length?b[b.length-1]:void 0;return c};d.track=function(b,c){var a;return null!=(a=f.Virtual._dependencies)?a.push({model:b,event:c}):void 0};d.prototype.runSafe=function(){try{return this.get.call(this.model,this.attr,this)}catch(b){return this.fail}};d.prototype.run=function(){f.Virtual.startTracking();this.result=this.hasOwnProperty("fail")?this.runSafe():this.get.call(this.model,this.attr,this);this.update(f.Virtual.stopTracking());
+this.trigger("change",this);return this.result};d.prototype.onChange=function(){return this.run()};d.prototype.update=function(b){var c,a,e,d;d=this.dependencies;a=0;for(e=d.length;a<e;a++)c=d[a],this.remove(c);a=0;for(e=b.length;a<e;a++)c=b[a],this.add(c);return this.dependencies=b};d.prototype.add=function(b){return b.model.on(b.event,this.onChange)};d.prototype.remove=function(b){return b.model.off(b.event,this.onChange)};d.prototype.get=function(b,c){return("function"===typeof c.reference?c.reference.call(this):
+c.reference).get(b)};d.prototype.set=function(b,c,a,e){return("function"===typeof e.reference?e.reference.call(this):e.reference).set(b,c)};return d}();return _.extend(f.Virtual.prototype,f.Events)})(Backbone)}).call(this);
+(function(){var h=function(f,d){return function(){return f.apply(d,arguments)}};(function(f){f.Binding=function(){function d(b){this.stop=h(this.stop,this);this.start=h(this.start,this);this.onViewChange=h(this.onViewChange,this);this.onCollectionChange=h(this.onCollectionChange,this);this.onModelChange=h(this.onModelChange,this);this.initialize=h(this.initialize,this);_.extend(this,b);this.initialize.apply(this,b.args)}d.prototype.initialize=function(){};d.prototype.onModelChange=function(){};d.prototype.onCollectionChange=
+function(){};d.prototype.onViewChange=function(){};d.prototype.start=function(){this.viewModel.on("change:"+this.attribute,this.onModelChange);return this.onModelChange()};d.prototype.stop=function(){return this.viewModel.off("change:"+this.attribute,this.onModelChange)};return d}();return f.Binding.extend=f.Model.extend})(Backbone)}).call(this);
+(function(){var h={}.hasOwnProperty,f=function(b,c){function a(){this.constructor=b}for(var e in c)h.call(c,e)&&(b[e]=c[e]);a.prototype=c.prototype;b.prototype=new a;b.__super__=c.prototype;return b},d=function(b,c){return function(){return b.apply(c,arguments)}};(function(b){b.Binding.visible=function(b){function a(){return a.__super__.constructor.apply(this,arguments)}f(a,b);a.prototype.initialize=function(a){this.attribute=a};a.prototype.onModelChange=function(){return this.viewModel.get(this.attribute)?
+$(this.node).show():$(this.node).hide()};return a}(b.Binding);b.Binding.text=function(b){function a(){return a.__super__.constructor.apply(this,arguments)}f(a,b);a.prototype.initialize=function(a){this.attribute=a};a.prototype.onModelChange=function(){var a;a=this.viewModel.get(this.attribute);return $(this.node).text(a)};return a}(b.Binding);b.Binding.val=function(b){function a(){return a.__super__.constructor.apply(this,arguments)}f(a,b);a.prototype.initialize=function(a){this.attribute=a};a.prototype.start=
+function(){a.__super__.start.apply(this,arguments);return $(this.node).on("keyup change",this.onViewChange)};a.prototype.onModelChange=function(){var a;a=this.viewModel.get(this.attribute);return $(this.node).val(a)};a.prototype.onViewChange=function(){return this.viewModel.set(this.attribute,$(this.node).val())};a.prototype.stop=function(){a.__super__.stop.apply(this,arguments);return $(this.node).off("keyup change",this.onViewChange)};return a}(b.Binding);b.Binding.css=function(b){function a(){return a.__super__.constructor.apply(this,
+arguments)}f(a,b);a.prototype.initialize=function(a,b,c){this.className=a;this.attribute=b;this.truth=null!=c?c:!0};a.prototype.onModelChange=function(){var a;a=this.viewModel.get(this.attribute);return Boolean(this.truth)===Boolean(a)?$(this.node).addClass(this.className):$(this.node).removeClass(this.className)};return a}(b.Binding);b.Binding.click=function(b){function a(){return a.__super__.constructor.apply(this,arguments)}f(a,b);a.prototype.initialize=function(){var a;a=_.toArray(arguments);
+this.callback=a.shift();return this.args=a};a.prototype.start=function(){return $(this.node).on("click",this.onViewChange)};a.prototype.onViewChange=function(a){var b;a.preventDefault();return(null!=(b=this.viewModel[this.callback])?b:this.viewModel.get(this.callback)).apply(this.viewModel,this.args)};a.prototype.stop=function(){return $(this.node).off("click",this.onViewChange)};return a}(b.Binding);return b.Binding.each=function(c){function a(){this.renderItem=d(this.renderItem,this);return a.__super__.constructor.apply(this,
+arguments)}f(a,c);a.prototype.initialize=function(a){this.attr=a;this.container=$(this.node);this.itemTemplate=this.container.html();return this.container.html("")};a.prototype.start=function(){this.viewModel.on("change:"+this.attr,this.onCollectionChange);return this.onCollectionChange()};a.prototype.onCollectionChange=function(){var a,c,d,f,h;this.container.html("");this.collection=this.viewModel.get(this.attr);if(this.collection instanceof b.Collection)return this.collection.off("add remove reset change create sort",
+this.onCollectionChange),this.collection.each(this.renderItem),this.collection.on("add remove reset change create sort",this.onCollectionChange);f=this.collection;h=[];c=0;for(d=f.length;c<d;c++)a=f[c],h.push(this.renderItem(a));return h};a.prototype.renderItem=function(a){var b,c,d,f,h;f=$(this.itemTemplate);h=[];c=0;for(d=f.length;c<d;c++)b=f[c],this.container.append(b),h.push(a.bindView(this.bindingAttr,b));return h};a.prototype.stop=function(){return this.viewModel.off("change:"+this.attr,this.onCollectionChange)};
+return a}(b.Binding)})(Backbone)}).call(this);
View
34 test/test_prod.html
@@ -15,15 +15,18 @@
<script src='../vendor/backbone-0.9.2.js'></script>
<!-- Backbone.ViewModel -->
- <script src='../dist/backbone.viewmodel-0.1.0.js'></script>
+ <script src='../dist/backbone.viewmodel-0.2.0.min.js'></script>
<!-- Test! -->
<script src="model.regression.js"></script>
<script src="viewmodel.regression.js"></script>
<script src="collection.regression.js"></script>
+ <script src='internals.qunit.js'></script>
<script src='bindings.qunit.js'></script>
<script src='virtual.qunit.js'></script>
<script src='integration.qunit.js'></script>
+ <script src='each.qunit.js'></script>
+ <script src='viewcollection.qunit.js'></script>
</head>
<body>
@@ -39,15 +42,32 @@ <h1 id="qunit-header"><a href="#">Backbone Speed Suite</a></h1>
<div id="jslitmus_container" style="margin: 20px 10px;"></div>
<div id='testBindings'>
- <p id='testVisible' data-test-visible='visible: isVisible'>visible</p>
- <p id='testText' data-test-text='text: name'>unset</p>
- <input id='testVal' data-test-val='val: name' value='unset' />
+ <p id='testVisible' data-test-visible='visible(isVisible)'>visible</p>
+ <p id='testText' data-test-text='text(name)'>unset</p>
+ <input id='testVal' data-test-val='val(name)' value='unset' />
+ <div id='testCss' class='existing' data-test-css='css(red, isRed); css(green, isGreen); css(blue, isBlue); css(transparent, isTransparent); css(white, isWhite)'></div>
+ <div id='testInvertedCss' data-test-css='css(red, isRed, false)'></div>
+ <a id='testClickA' href='#a' data-click-a='click(clicked)'>A</a>
+ <a id='testClickB' href='#b' data-click-b='click(clicked)'>B</a>
+ <a id='testClickAB' href='#ab' data-click-a='click(clicked)' data-click-b='click(clicked)'>AB</a>
+ </div>
+
+ <div id='eachBinding'>
+ <ul id='simpleEach' data-each-simple='each(listItems)'>
+ <li data-each-simple='text(label)'>default content</li>
+ </ul>
+ <div id='fragEach' data-each-frag='each(items)'>
+ <h1 data-each-frag='text(name)'></h1>
+ <p data-each-frag='css(female, isFemale); css(male, isMale); text(description)'></p>
+ <a href='#' data-each-frag='attr(href, mailLink'>Email</a>
+ <a href='#' data-each-frag='click(removeMe)'>Remove</a>
+ </div>
</div>
<div id='integrationTests'>
- <p id='intVisible' data-bind-int='visible: isAdult'>Porn goes here!</p>
- <p id='intText' data-bind-int='text: fullname'></p>
- <input id='intVal' data-bind-int='val: occupation'></p>
+ <p id='intVisible' data-bind-int='visible(isAdult)'>Porn goes here!</p>
+ <p id='intText' data-bind-int='text(fullname)'></p>
+ <input id='intVal' data-bind-int='val(occupation)'></p>
</div>
</body>
Please sign in to comment.
Something went wrong with that request. Please try again.