Skip to content

Commit

Permalink
Merge pull request #18 from Ke-/master
Browse files Browse the repository at this point in the history
Faster onEachEvent event (including namespaces)
  • Loading branch information
GianlucaGuarini committed Apr 7, 2016
2 parents e379c38 + 1adffbd commit a235a44
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/index.js
Expand Up @@ -18,10 +18,14 @@ var observable = function(el) {
*/
var callbacks = {},
slice = Array.prototype.slice,
onEachEvent = function(e, fn) { e.replace(EVENTS_GROUP_REGEX, function(name, pos, ns) {
name = name.split('.')
fn(name[0], pos, name.splice(1).join('.'))
})}
onEachEvent = function(e, fn) {
var es = e.split(' '), l = es.length, i = 0, name, indx
for (; i < l; i++) {
name = es[i]
indx = name.indexOf('.')
if (name) fn( ~indx ? name.substring(0, indx) : name, i, ~indx ? name.slice(indx + 1) : null)
}
}

// extend the object adding the observable methods
Object.defineProperties(el, {
Expand Down

0 comments on commit a235a44

Please sign in to comment.