Skip to content

Commit

Permalink
faster node collection iteration.
Browse files Browse the repository at this point in the history
  • Loading branch information
sorvell committed Sep 17, 2013
1 parent 5c5df3d commit 4ea4775
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/declaration/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@
// inherit instance attributes
var clonable = this.prototype._instanceAttributes;
// merge attributes from element
this.attributes.forEach(function(a) {
var a$ = this.attributes;
for (var i=0, l=a$.length, a; (i<l) && (a=a$[i]); i++) {
if (this.isInstanceAttribute(a.name)) {
clonable[a.name] = a.value;
}
}, this);
}
},
isInstanceAttribute: function(name) {
return !this.blackList[name] && name.slice(0,3) !== 'on-';
Expand Down
17 changes: 10 additions & 7 deletions src/declaration/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@
},
parseLocalEvents: function() {
// extract data from all templates into delegates
this.querySelectorAll('template').forEach(function(t) {
var t$ = this.querySelectorAll('template');
for (var i=0, l=t$.length, t; (i<l) && (t=t$[i]); i++) {
// store delegate information directly on template
t.delegates = {};
// acquire delegates from entire subtree at t
this.accumulateTemplatedEvents(t, t.delegates);
log.events && console.log('[%s] parseLocalEvents:', this.attributes.name.value, t.delegates);
}, this);
};
},
accumulateTemplatedEvents: function(node, events) {
if (node.localName === 'template') {
Expand All @@ -59,9 +60,10 @@
}
},
accumulateChildEvents: function(node, events) {
node.childNodes.forEach(function(n) {
var n$ = node.childNodes;
for (var i=0, l=n$.length, n; (i<l) && (n=n$[i]); i++) {
this.accumulateEvents(n, events);
}, this);
}
},
accumulateEvents: function(node, events) {
this.accumulateAttributeEvents(node, events);
Expand All @@ -70,12 +72,13 @@
return events;
},
accumulateAttributeEvents: function(node, events) {
if (node.attributes) {
node.attributes.forEach(function(a) {
var a$ = node.attributes;
if (a$) {
for (var i=0, l=a$.length, a; (i<l) && (a=a$[i]); i++) {
if (hasEventPrefix(a.name)) {
this.accumulateEvent(removeEventPrefix(a.name), events);
}
}, this);
}
}
},
accumulateEvent: function(name, events) {
Expand Down

0 comments on commit 4ea4775

Please sign in to comment.