e0044f13 by Nicklas Ansman Giertz

Avoid unnecessary return values

1 parent 67c5564b
......@@ -161,7 +161,7 @@
};
View.prototype.build = function() {
var bindingRegExp, el, eventRegExp, iterationRegExp, iterator, node, parseNode, skipNodes, _i, _len, _ref, _results,
var bindingRegExp, el, eventRegExp, iterationRegExp, iterator, node, parseNode, skipNodes, _i, _j, _len, _len1, _ref, _ref1,
_this = this;
this.bindings = [];
skipNodes = [];
......@@ -170,7 +170,7 @@
eventRegExp = /^on-/;
iterationRegExp = /^each-/;
parseNode = function(node) {
var a, attribute, binding, context, ctx, dependencies, keypath, model, n, options, path, pipe, pipes, splitPath, type, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1, _ref2, _results;
var a, attribute, binding, context, ctx, dependencies, keypath, model, n, options, path, pipe, pipes, splitPath, type, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref, _ref1, _ref2;
if (__indexOf.call(skipNodes, node) < 0) {
_ref = node.attributes;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
......@@ -190,31 +190,30 @@
}
}
_ref2 = iterator || node.attributes;
_results = [];
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
attribute = _ref2[_k];
if (bindingRegExp.test(attribute.name)) {
options = {};
type = attribute.name.replace(bindingRegExp, '');
pipes = (function() {
var _l, _len3, _ref3, _results1;
var _l, _len3, _ref3, _results;
_ref3 = attribute.value.split('|');
_results1 = [];
_results = [];
for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) {
pipe = _ref3[_l];
_results1.push(pipe.trim());
_results.push(pipe.trim());
}
return _results1;
return _results;
})();
context = (function() {
var _l, _len3, _ref3, _results1;
var _l, _len3, _ref3, _results;
_ref3 = pipes.shift().split('>');
_results1 = [];
_results = [];
for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) {
ctx = _ref3[_l];
_results1.push(ctx.trim());
_results.push(ctx.trim());
}
return _results1;
return _results;
})();
path = context.shift();
splitPath = path.split(/\.|:/);
......@@ -244,31 +243,21 @@
a = iterator[_l];
node.removeAttribute(a.name);
}
_results.push(iterator = null);
} else {
_results.push(void 0);
iterator = null;
}
}
return _results;
}
};
_ref = this.els;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
el = _ref[_i];
parseNode(el);
_results.push((function() {
var _j, _len1, _ref1, _results1;
_ref1 = el.getElementsByTagName('*');
_results1 = [];
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
node = _ref1[_j];
_results1.push(parseNode(node));
parseNode(node);
}
return _results1;
})());
}
return _results;
};
View.prototype.bind = function() {
......@@ -436,16 +425,14 @@
formatters: Rivets.formatters,
config: Rivets.config,
configure: function(options) {
var property, value, _results;
var property, value;
if (options == null) {
options = {};
}
_results = [];
for (property in options) {
value = options[property];
_results.push(Rivets.config[property] = value);
Rivets.config[property] = value;
}
return _results;
},
bind: function(el, models) {
var view;
......
......@@ -2,4 +2,4 @@
// version: 0.3.2
// author: Michael Richards
// license: MIT
(function(){var a,b,c,d,e,f,g,h,i=function(a,b){return function(){return a.apply(b,arguments)}},j=[].slice,k=[].indexOf||function(a){for(var b=0,c=this.length;b<c;b++)if(b in this&&this[b]===a)return b;return-1};a={},String.prototype.trim||(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}),a.Binding=function(){function g(c,e,g,h,j){this.el=c,this.type=e,this.model=g,this.keypath=h,this.options=j!=null?j:{},this.unbind=i(this.unbind,this),this.publish=i(this.publish,this),this.bind=i(this.bind,this),this.set=i(this.set,this),this.formattedValue=i(this.formattedValue,this),this.routine=function(){switch(this.options.special){case"event":return d(this.type);case"iteration":return f(this.type);default:return a.routines[this.type]||b(this.type)}}.call(this),this.formatters=this.options.formatters||[]}return g.prototype.bidirectionals=["value","checked","unchecked"],g.prototype.formattedValue=function(b){var c,d,e,f,g,h,i,k;h=this.formatters;for(f=0,g=h.length;f<g;f++)d=h[f],c=d.split(/\s+/),e=c.shift(),b=this.model[e]instanceof Function?(i=this.model)[e].apply(i,[b].concat(j.call(c))):a.formatters[e]?(k=a.formatters)[e].apply(k,[b].concat(j.call(c))):void 0;return b},g.prototype.set=function(a){return a=this.formattedValue(a),this.options.special==="event"?(this.routine(this.el,a,this.currentListener),this.currentListener=a):this.options.special==="iteration"?this.routine(this.el,a,this):(a instanceof Function&&(a=a.call(this.model)),this.routine(this.el,a))},g.prototype.bind=function(){var b,d,e,f,g,h,i,j=this;this.options.bypass?this.set(this.model[this.keypath]):(a.config.adapter.subscribe(this.model,this.keypath,this.set),a.config.preloadData&&this.set(a.config.adapter.read(this.model,this.keypath)));if((g=this.options.dependencies)!=null?g.length:void 0){this.dependencyCallbacks={},h=this.options.dependencies;for(e=0,f=h.length;e<f;e++)d=h[e],b=this.dependencyCallbacks[d]=function(b){return j.set(j.options.bypass?j.model[j.keypath]:a.config.adapter.read(j.model,j.keypath))},a.config.adapter.subscribe(this.model,d,b)}if(i=this.type,k.call(this.bidirectionals,i)>=0)return c(this.el,"change",this.publish)},g.prototype.publish=function(b){var c;return c=b.target||b.srcElement,a.config.adapter.publish(this.model,this.keypath,e(c))},g.prototype.unbind=function(){var b,c,d,e,f,g,h;if(!this.options.bypass){a.config.adapter.unsubscribe(this.model,this.keypath,this.set);if((f=this.options.dependencies)!=null?f.length:void 0){g=this.options.dependencies;for(d=0,e=g.length;d<e;d++)c=g[d],b=this.dependencyCallbacks[c],a.config.adapter.unsubscribe(this.model,c,b)}if(h=this.type,k.call(this.bidirectionals,h)>=0)return this.el.removeEventListener("change",this.publish)}},g}(),a.View=function(){function b(a,b){this.els=a,this.models=b,this.unbind=i(this.unbind,this),this.bind=i(this.bind,this),this.build=i(this.build,this),this.bindingRegExp=i(this.bindingRegExp,this),this.els.jquery||this.els instanceof Array||(this.els=[this.els]),this.build()}return b.prototype.bindingRegExp=function(){var b;return b=a.config.prefix,b?new RegExp("^data-"+b+"-"):/^data-/},b.prototype.build=function(){var b,c,d,e,f,g,h,i,j,l,m,n,o=this;this.bindings=[],i=[],f=null,b=this.bindingRegExp(),d=/^on-/,e=/^each-/,h=function(c){var g,h,j,l,m,n,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J;if(k.call(i,c)<0){G=c.attributes;for(y=0,C=G.length;y<C;y++){h=G[y];if(b.test(h.name)){x=h.name.replace(b,"");if(e.test(x)&&!o.models[x.replace(e,"")]){H=c.getElementsByTagName("*");for(z=0,D=H.length;z<D;z++)r=H[z],i.push(r);f=[h]}}}I=f||c.attributes,J=[];for(A=0,E=I.length;A<E;A++){h=I[A];if(b.test(h.name)){s={},x=h.name.replace(b,""),v=function(){var a,b,c,d;c=h.value.split("|"),d=[];for(a=0,b=c.length;a<b;a++)u=c[a],d.push(u.trim());return d}(),l=function(){var a,b,c,d;c=v.shift().split(">"),d=[];for(a=0,b=c.length;a<b;a++)m=c[a],d.push(m.trim());return d}(),t=l.shift(),w=t.split(/\.|:/),s.formatters=v,q=o.models[w.shift()],s.bypass=t.indexOf(":")!==-1,p=w.join();if(q){if(n=l.shift())s.dependencies=n.split(/\s+/);d.test(x)&&(x=x.replace(d,""),s.special="event"),e.test(x)&&(x=x.replace(e,""),s.special="iteration"),j=new a.Binding(c,x,q,p,s),j.view=o,o.bindings.push(j)}}if(f){for(B=0,F=f.length;B<F;B++)g=f[B],c.removeAttribute(g.name);J.push(f=null)}else J.push(void 0)}return J}},m=this.els,n=[];for(j=0,l=m.length;j<l;j++)c=m[j],h(c),n.push(function(){var a,b,d,e;d=c.getElementsByTagName("*"),e=[];for(a=0,b=d.length;a<b;a++)g=d[a],e.push(h(g));return e}());return n},b.prototype.bind=function(){var a,b,c,d,e;d=this.bindings,e=[];for(b=0,c=d.length;b<c;b++)a=d[b],e.push(a.bind());return e},b.prototype.unbind=function(){var a,b,c,d,e;d=this.bindings,e=[];for(b=0,c=d.length;b<c;b++)a=d[b],e.push(a.unbind());return e},b}(),c=function(a,b,c){return window.addEventListener?a.addEventListener(b,c,!1):(b="on"+b,a.attachEvent(b,c))},h=function(a,b,c){return window.removeEventListener?a.removeEventListener(b,c,!1):(b="on"+b,a.detachEvent(b,c))},e=function(a){switch(a.type){case"checkbox":return a.checked;default:return a.value}},d=function(a){return function(b,d,e){d&&c(b,a,d);if(e)return h(b,a,e)}},f=function(a){return function(b,c,d){var e,f,h,i,j,k,l,m,n,o,p,q,r,s;if(d.iterated!=null){q=d.iterated;for(m=0,o=q.length;m<o;m++)i=q[m],i.view.unbind(),i.el.parentNode.removeChild(i.el)}else d.marker=document.createComment(" rivets: each-"+a+" "),b.parentNode.insertBefore(d.marker,b),b.parentNode.removeChild(b);d.iterated=[],s=[];for(n=0,p=c.length;n<p;n++){f=c[n],e={},r=d.view.models;for(k in r)j=r[k],e[k]=j;e[a]=f,h=b.cloneNode(!0),l=d.iterated[d.iterated.length-1]||d.marker,d.marker.parentNode.insertBefore(h,l.nextSibling),s.push(d.iterated.push({el:h,view:g.bind(h,e)}))}return s}},b=function(a){return function(b,c){return c?b.setAttribute(a,c):b.removeAttribute(a)}},a.routines={enabled:function(a,b){return a.disabled=!b},disabled:function(a,b){return a.disabled=!!b},checked:function(a,b){return a.type==="radio"?a.checked=a.value===b:a.checked=!!b},unchecked:function(a,b){return a.type==="radio"?a.checked=a.value!==b:a.checked=!b},show:function(a,b){return a.style.display=b?"":"none"},hide:function(a,b){return a.style.display=b?"none":""},html:function(a,b){return a.innerHTML=b!=null?b:""},value:function(a,b){return a.value=b!=null?b:""},text:function(a,b){return a.innerText!=null?a.innerText=b!=null?b:"":a.textContent=b!=null?b:""}},a.config={preloadData:!0},a.formatters={},g={routines:a.routines,formatters:a.formatters,config:a.config,configure:function(b){var c,d,e;b==null&&(b={}),e=[];for(c in b)d=b[c],e.push(a.config[c]=d);return e},bind:function(b,c){var d;return c==null&&(c={}),d=new a.View(b,c),d.bind(),d}},typeof module!="undefined"&&module!==null?module.exports=g:this.rivets=g}).call(this);
\ No newline at end of file
(function(){var a,b,c,d,e,f,g,h,i=function(a,b){return function(){return a.apply(b,arguments)}},j=[].slice,k=[].indexOf||function(a){for(var b=0,c=this.length;b<c;b++)if(b in this&&this[b]===a)return b;return-1};a={},String.prototype.trim||(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}),a.Binding=function(){function g(c,e,g,h,j){this.el=c,this.type=e,this.model=g,this.keypath=h,this.options=j!=null?j:{},this.unbind=i(this.unbind,this),this.publish=i(this.publish,this),this.bind=i(this.bind,this),this.set=i(this.set,this),this.formattedValue=i(this.formattedValue,this),this.routine=function(){switch(this.options.special){case"event":return d(this.type);case"iteration":return f(this.type);default:return a.routines[this.type]||b(this.type)}}.call(this),this.formatters=this.options.formatters||[]}return g.prototype.bidirectionals=["value","checked","unchecked"],g.prototype.formattedValue=function(b){var c,d,e,f,g,h,i,k;h=this.formatters;for(f=0,g=h.length;f<g;f++)d=h[f],c=d.split(/\s+/),e=c.shift(),b=this.model[e]instanceof Function?(i=this.model)[e].apply(i,[b].concat(j.call(c))):a.formatters[e]?(k=a.formatters)[e].apply(k,[b].concat(j.call(c))):void 0;return b},g.prototype.set=function(a){return a=this.formattedValue(a),this.options.special==="event"?(this.routine(this.el,a,this.currentListener),this.currentListener=a):this.options.special==="iteration"?this.routine(this.el,a,this):(a instanceof Function&&(a=a.call(this.model)),this.routine(this.el,a))},g.prototype.bind=function(){var b,d,e,f,g,h,i,j=this;this.options.bypass?this.set(this.model[this.keypath]):(a.config.adapter.subscribe(this.model,this.keypath,this.set),a.config.preloadData&&this.set(a.config.adapter.read(this.model,this.keypath)));if((g=this.options.dependencies)!=null?g.length:void 0){this.dependencyCallbacks={},h=this.options.dependencies;for(e=0,f=h.length;e<f;e++)d=h[e],b=this.dependencyCallbacks[d]=function(b){return j.set(j.options.bypass?j.model[j.keypath]:a.config.adapter.read(j.model,j.keypath))},a.config.adapter.subscribe(this.model,d,b)}if(i=this.type,k.call(this.bidirectionals,i)>=0)return c(this.el,"change",this.publish)},g.prototype.publish=function(b){var c;return c=b.target||b.srcElement,a.config.adapter.publish(this.model,this.keypath,e(c))},g.prototype.unbind=function(){var b,c,d,e,f,g,h;if(!this.options.bypass){a.config.adapter.unsubscribe(this.model,this.keypath,this.set);if((f=this.options.dependencies)!=null?f.length:void 0){g=this.options.dependencies;for(d=0,e=g.length;d<e;d++)c=g[d],b=this.dependencyCallbacks[c],a.config.adapter.unsubscribe(this.model,c,b)}if(h=this.type,k.call(this.bidirectionals,h)>=0)return this.el.removeEventListener("change",this.publish)}},g}(),a.View=function(){function b(a,b){this.els=a,this.models=b,this.unbind=i(this.unbind,this),this.bind=i(this.bind,this),this.build=i(this.build,this),this.bindingRegExp=i(this.bindingRegExp,this),this.els.jquery||this.els instanceof Array||(this.els=[this.els]),this.build()}return b.prototype.bindingRegExp=function(){var b;return b=a.config.prefix,b?new RegExp("^data-"+b+"-"):/^data-/},b.prototype.build=function(){var b,c,d,e,f,g,h,i,j,l,m,n,o,p,q=this;this.bindings=[],i=[],f=null,b=this.bindingRegExp(),d=/^on-/,e=/^each-/,h=function(c){var g,h,j,l,m,n,o,p,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I;if(k.call(i,c)<0){G=c.attributes;for(y=0,C=G.length;y<C;y++){h=G[y];if(b.test(h.name)){x=h.name.replace(b,"");if(e.test(x)&&!q.models[x.replace(e,"")]){H=c.getElementsByTagName("*");for(z=0,D=H.length;z<D;z++)r=H[z],i.push(r);f=[h]}}}I=f||c.attributes;for(A=0,E=I.length;A<E;A++){h=I[A];if(b.test(h.name)){s={},x=h.name.replace(b,""),v=function(){var a,b,c,d;c=h.value.split("|"),d=[];for(a=0,b=c.length;a<b;a++)u=c[a],d.push(u.trim());return d}(),l=function(){var a,b,c,d;c=v.shift().split(">"),d=[];for(a=0,b=c.length;a<b;a++)m=c[a],d.push(m.trim());return d}(),t=l.shift(),w=t.split(/\.|:/),s.formatters=v,p=q.models[w.shift()],s.bypass=t.indexOf(":")!==-1,o=w.join();if(p){if(n=l.shift())s.dependencies=n.split(/\s+/);d.test(x)&&(x=x.replace(d,""),s.special="event"),e.test(x)&&(x=x.replace(e,""),s.special="iteration"),j=new a.Binding(c,x,p,o,s),j.view=q,q.bindings.push(j)}}if(f){for(B=0,F=f.length;B<F;B++)g=f[B],c.removeAttribute(g.name);f=null}}}},o=this.els;for(j=0,m=o.length;j<m;j++){c=o[j],h(c),p=c.getElementsByTagName("*");for(l=0,n=p.length;l<n;l++)g=p[l],h(g)}},b.prototype.bind=function(){var a,b,c,d,e;d=this.bindings,e=[];for(b=0,c=d.length;b<c;b++)a=d[b],e.push(a.bind());return e},b.prototype.unbind=function(){var a,b,c,d,e;d=this.bindings,e=[];for(b=0,c=d.length;b<c;b++)a=d[b],e.push(a.unbind());return e},b}(),c=function(a,b,c){return window.addEventListener?a.addEventListener(b,c,!1):(b="on"+b,a.attachEvent(b,c))},h=function(a,b,c){return window.removeEventListener?a.removeEventListener(b,c,!1):(b="on"+b,a.detachEvent(b,c))},e=function(a){switch(a.type){case"checkbox":return a.checked;default:return a.value}},d=function(a){return function(b,d,e){d&&c(b,a,d);if(e)return h(b,a,e)}},f=function(a){return function(b,c,d){var e,f,h,i,j,k,l,m,n,o,p,q,r,s;if(d.iterated!=null){q=d.iterated;for(m=0,o=q.length;m<o;m++)i=q[m],i.view.unbind(),i.el.parentNode.removeChild(i.el)}else d.marker=document.createComment(" rivets: each-"+a+" "),b.parentNode.insertBefore(d.marker,b),b.parentNode.removeChild(b);d.iterated=[],s=[];for(n=0,p=c.length;n<p;n++){f=c[n],e={},r=d.view.models;for(k in r)j=r[k],e[k]=j;e[a]=f,h=b.cloneNode(!0),l=d.iterated[d.iterated.length-1]||d.marker,d.marker.parentNode.insertBefore(h,l.nextSibling),s.push(d.iterated.push({el:h,view:g.bind(h,e)}))}return s}},b=function(a){return function(b,c){return c?b.setAttribute(a,c):b.removeAttribute(a)}},a.routines={enabled:function(a,b){return a.disabled=!b},disabled:function(a,b){return a.disabled=!!b},checked:function(a,b){return a.type==="radio"?a.checked=a.value===b:a.checked=!!b},unchecked:function(a,b){return a.type==="radio"?a.checked=a.value!==b:a.checked=!b},show:function(a,b){return a.style.display=b?"":"none"},hide:function(a,b){return a.style.display=b?"none":""},html:function(a,b){return a.innerHTML=b!=null?b:""},value:function(a,b){return a.value=b!=null?b:""},text:function(a,b){return a.innerText!=null?a.innerText=b!=null?b:"":a.textContent=b!=null?b:""}},a.config={preloadData:!0},a.formatters={},g={routines:a.routines,formatters:a.formatters,config:a.config,configure:function(b){var c,d;b==null&&(b={});for(c in b)d=b[c],a.config[c]=d},bind:function(b,c){var d;return c==null&&(c={}),d=new a.View(b,c),d.bind(),d}},typeof module!="undefined"&&module!==null?module.exports=g:this.rivets=g}).call(this);
\ No newline at end of file
......
......@@ -165,10 +165,12 @@ class Rivets.View
if iterator
node.removeAttribute(a.name) for a in iterator
iterator = null
return
for el in @els
parseNode el
parseNode node for node in el.getElementsByTagName '*'
return
# Binds all of the current bindings for this view.
bind: =>
......@@ -291,6 +293,7 @@ rivets =
configure: (options={}) ->
for property, value of options
Rivets.config[property] = value
return
# Binds a set of model objects to a parent DOM element. Returns a Rivets.View
# instance.
......