b4993914 by Michael Richards

Replace Array::map call with a list comprehension and remove the polypill.

1 parent 1b2c90bc
...@@ -12,30 +12,6 @@ ...@@ -12,30 +12,6 @@
12 }; 12 };
13 } 13 }
14 14
15 if (!Array.prototype.map) {
16 Array.prototype.map = function(callback) {
17 var A, O, T, k, len;
18 if (this === null) {
19 throw new TypeError("Can't convert " + this + " to object");
20 }
21 O = Object(this);
22 len = O.length >>> 0;
23 if (typeof callback !== 'function') {
24 throw new TypeError("" + callback + " is not a function");
25 }
26 T = arguments[1];
27 A = new Array(len);
28 k = 0;
29 while (k < len) {
30 if (k in O) {
31 A[k] = callbackfn.call(T, O[k], k, O);
32 }
33 k++;
34 }
35 return A;
36 };
37 }
38
39 Rivets.Binding = (function() { 15 Rivets.Binding = (function() {
40 16
41 function Binding(el, type, model, keypath, formatters) { 17 function Binding(el, type, model, keypath, formatters) {
...@@ -113,7 +89,7 @@ ...@@ -113,7 +89,7 @@
113 }; 89 };
114 90
115 View.prototype.build = function() { 91 View.prototype.build = function() {
116 var attribute, bindingRegExp, keypath, model, node, path, pipes, type, _i, _len, _ref, _results; 92 var attribute, bindingRegExp, keypath, model, node, path, pipe, pipes, type, _i, _len, _ref, _results;
117 this.bindings = []; 93 this.bindings = [];
118 bindingRegExp = this.bindingRegExp(); 94 bindingRegExp = this.bindingRegExp();
119 _ref = this.el.getElementsByTagName('*'); 95 _ref = this.el.getElementsByTagName('*');
...@@ -128,9 +104,16 @@ ...@@ -128,9 +104,16 @@
128 attribute = _ref1[_j]; 104 attribute = _ref1[_j];
129 if (bindingRegExp.test(attribute.name)) { 105 if (bindingRegExp.test(attribute.name)) {
130 type = attribute.name.replace(bindingRegExp, ''); 106 type = attribute.name.replace(bindingRegExp, '');
131 pipes = attribute.value.split('|').map(function(pipe) { 107 pipes = (function() {
132 return pipe.trim(); 108 var _k, _len2, _ref2, _results2;
133 }); 109 _ref2 = attribute.value.split('|');
110 _results2 = [];
111 for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
112 pipe = _ref2[_k];
113 _results2.push(pipe.trim());
114 }
115 return _results2;
116 })();
134 path = pipes.shift().split('.'); 117 path = pipes.shift().split('.');
135 model = this.models[path.shift()]; 118 model = this.models[path.shift()];
136 keypath = path.join('.'); 119 keypath = path.join('.');
......
...@@ -9,26 +9,6 @@ Rivets = {} ...@@ -9,26 +9,6 @@ Rivets = {}
9 # Polyfill For String::trim. 9 # Polyfill For String::trim.
10 unless String::trim then String::trim = -> @replace /^\s+|\s+$/g, "" 10 unless String::trim then String::trim = -> @replace /^\s+|\s+$/g, ""
11 11
12 # Polyfill For Array::map
13 unless Array::map
14 Array::map = (callback) ->
15 if this is null
16 throw new TypeError "Can't convert #{this} to object"
17 O = Object(this)
18 len = O.length >>> 0
19
20 throw new TypeError "#{callback} is not a function" unless typeof callback is 'function'
21
22 T = arguments[1]
23 A = new Array(len)
24 k = 0;
25
26 while k < len
27 A[k] = callbackfn.call(T, O[k], k, O) if k of O
28 k++
29
30 return A
31
32 # A single binding between a model attribute and a DOM element. 12 # A single binding between a model attribute and a DOM element.
33 class Rivets.Binding 13 class Rivets.Binding
34 # All information about the binding is passed into the constructor; the DOM 14 # All information about the binding is passed into the constructor; the DOM
...@@ -88,7 +68,7 @@ class Rivets.View ...@@ -88,7 +68,7 @@ class Rivets.View
88 for attribute in node.attributes 68 for attribute in node.attributes
89 if bindingRegExp.test attribute.name 69 if bindingRegExp.test attribute.name
90 type = attribute.name.replace bindingRegExp, '' 70 type = attribute.name.replace bindingRegExp, ''
91 pipes = attribute.value.split('|').map (pipe) -> pipe.trim() 71 pipes = (pipe.trim() for pipe in attribute.value.split '|')
92 path = pipes.shift().split '.' 72 path = pipes.shift().split '.'
93 model = @models[path.shift()] 73 model = @models[path.shift()]
94 keypath = path.join '.' 74 keypath = path.join '.'
......