Refactor element parsing in the exposed bind function.
Showing
2 changed files
with
27 additions
and
36 deletions
... | @@ -77,36 +77,34 @@ | ... | @@ -77,36 +77,34 @@ |
77 | 77 | ||
78 | rivets = { | 78 | rivets = { |
79 | bind: function(el, adapter, contexts) { | 79 | bind: function(el, adapter, contexts) { |
80 | var nodes, _i, _ref, _results; | 80 | var attribute, context, keypath, node, path, type, _i, _len, _ref, _results; |
81 | if (contexts == null) { | 81 | if (contexts == null) { |
82 | contexts = {}; | 82 | contexts = {}; |
83 | } | 83 | } |
84 | nodes = el.getElementsByTagName('*'); | 84 | _ref = el.getElementsByTagName('*'); |
85 | return (function() { | 85 | _results = []; |
86 | _results = []; | 86 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { |
87 | for (var _i = 0, _ref = nodes.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; 0 <= _ref ? _i++ : _i--){ _results.push(_i); } | 87 | node = _ref[_i]; |
88 | return _results; | 88 | _results.push((function() { |
89 | }).apply(this).forEach(function(n) { | 89 | var _j, _len1, _ref1, _results1; |
90 | var node, _i, _ref, _results; | 90 | _ref1 = node.attributes; |
91 | node = nodes[n]; | 91 | _results1 = []; |
92 | if (node.attributes.length > 0) { | 92 | for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { |
93 | return (function() { | 93 | attribute = _ref1[_j]; |
94 | _results = []; | ||
95 | for (var _i = 0, _ref = node.attributes.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; 0 <= _ref ? _i++ : _i--){ _results.push(_i); } | ||
96 | return _results; | ||
97 | }).apply(this).forEach(function(n) { | ||
98 | var attribute, context, keypath, path, type; | ||
99 | attribute = node.attributes[n]; | ||
100 | if (/^data-/.test(attribute.name)) { | 94 | if (/^data-/.test(attribute.name)) { |
101 | type = attribute.name.replace('data-', ''); | 95 | type = attribute.name.replace('data-', ''); |
102 | path = attribute.value.split('.'); | 96 | path = attribute.value.split('.'); |
103 | context = path.shift(); | 97 | context = path.shift(); |
104 | keypath = path.join('.'); | 98 | keypath = path.join('.'); |
105 | return registerBinding(node, adapter, type, contexts[context], keypath); | 99 | _results1.push(registerBinding(node, adapter, type, contexts[context], keypath)); |
100 | } else { | ||
101 | _results1.push(void 0); | ||
106 | } | 102 | } |
107 | }); | 103 | } |
108 | } | 104 | return _results1; |
109 | }); | 105 | })()); |
106 | } | ||
107 | return _results; | ||
110 | } | 108 | } |
111 | }; | 109 | }; |
112 | 110 | ... | ... |
... | @@ -53,21 +53,14 @@ bidirectionals = ['value', 'checked', 'unchecked', 'selected', 'unselected'] | ... | @@ -53,21 +53,14 @@ bidirectionals = ['value', 'checked', 'unchecked', 'selected', 'unselected'] |
53 | 53 | ||
54 | rivets = | 54 | rivets = |
55 | bind: (el, adapter, contexts = {}) -> | 55 | bind: (el, adapter, contexts = {}) -> |
56 | nodes = el.getElementsByTagName '*' | 56 | for node in el.getElementsByTagName '*' |
57 | 57 | for attribute in node.attributes | |
58 | [0..(nodes.length - 1)].forEach (n) -> | 58 | if /^data-/.test attribute.name |
59 | node = nodes[n] | 59 | type = attribute.name.replace 'data-', '' |
60 | 60 | path = attribute.value.split '.' | |
61 | if node.attributes.length > 0 | 61 | context = path.shift() |
62 | [0..(node.attributes.length - 1)].forEach (n) -> | 62 | keypath = path.join '.' |
63 | attribute = node.attributes[n] | 63 | registerBinding node, adapter, type, contexts[context], keypath |
64 | |||
65 | if /^data-/.test attribute.name | ||
66 | type = attribute.name.replace 'data-', '' | ||
67 | path = attribute.value.split '.' | ||
68 | context = path.shift() | ||
69 | keypath = path.join '.' | ||
70 | registerBinding node, adapter, type, contexts[context], keypath | ||
71 | 64 | ||
72 | if module? | 65 | if module? |
73 | module.exports = rivets | 66 | module.exports = rivets | ... | ... |
-
Please register or sign in to post a comment