Skip to content

Commit

Permalink
feat: limit node listeners to one per node
Browse files Browse the repository at this point in the history
  • Loading branch information
troch committed Jul 20, 2015
1 parent bef0f8c commit a4ed868
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions modules/Router5.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,14 @@ export default class Router5 {
/**
* @private
*/
_addListener(name, cb) {
_addListener(name, cb, replace) {
let normalizedName = name.replace(/^(\*|\^|=)/, '')
if (normalizedName) {
let segments = this.rootNode.getSegmentsByName(normalizedName)
if (!segments) console.warn(`No route found for ${normalizedName}, listener might never be called!`)
}
if (!this._cbs[name]) this._cbs[name] = []
this._cbs[name].push(cb)
this._cbs[name] = (replace ? [] : this._cbs[name]).concat(cb)
return this
}

Expand Down Expand Up @@ -233,7 +233,7 @@ export default class Router5 {
* @return {Router5} The router instance
*/
addNodeListener(name, cb) {
return this._addListener('^' + name, cb);
return this._addListener('^' + name, cb, true);
}

/**
Expand Down

0 comments on commit a4ed868

Please sign in to comment.