Skip to content

Commit

Permalink
feat: don't bind listeners to router instance
Browse files Browse the repository at this point in the history
  • Loading branch information
troch committed Jul 9, 2015
1 parent f402ad0 commit 1a7246d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 24 deletions.
14 changes: 8 additions & 6 deletions dist/browser/router5.js
Original file line number Diff line number Diff line change
Expand Up @@ -662,11 +662,9 @@ var Router5 = (function () {
* @private
*/
value: function _invokeListeners(name, newState, oldState) {
var _this = this;

if (!this.callbacks[name]) return;
this.callbacks[name].forEach(function (cb) {
cb.call(_this, newState, oldState);
return cb(newState, oldState);
});
}
}, {
Expand Down Expand Up @@ -841,11 +839,15 @@ var Router5 = (function () {
}, {
key: '_transition',

/**
*
*/

/**
* @private
*/
value: function _transition(toState, fromState) {
var _this2 = this;
var _this = this;

if (!fromState) {
this.lastKnownState = toState;
Expand All @@ -864,7 +866,7 @@ var Router5 = (function () {
}

cannotDeactivate = fromStateIds.slice(i).reverse().map(function (id) {
return _this2.activeComponents[id];
return _this.activeComponents[id];
}).filter(function (comp) {
return comp && comp.canDeactivate;
}).some(function (comp) {
Expand All @@ -873,7 +875,7 @@ var Router5 = (function () {

if (!cannotDeactivate) {
this.lastKnownState = toState;
this._invokeListeners(i > 0 ? '^' + fromStateIds[i - 1] : '^', toState, fromState);
this._invokeListeners('^' + (i > 0 ? fromStateIds[i - 1] : ''), toState, fromState);
this._invokeListeners('=' + toState.name, toState, fromState);
this._invokeListeners('*', toState, fromState);
}
Expand Down
2 changes: 1 addition & 1 deletion dist/browser/router5.min.js

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions dist/commonjs/router5.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,9 @@ var Router5 = (function () {
* @private
*/
value: function _invokeListeners(name, newState, oldState) {
var _this = this;

if (!this.callbacks[name]) return;
this.callbacks[name].forEach(function (cb) {
cb.call(_this, newState, oldState);
return cb(newState, oldState);
});
}
}, {
Expand Down Expand Up @@ -399,11 +397,15 @@ var Router5 = (function () {
}, {
key: '_transition',

/**
*
*/

/**
* @private
*/
value: function _transition(toState, fromState) {
var _this2 = this;
var _this = this;

if (!fromState) {
this.lastKnownState = toState;
Expand All @@ -422,7 +424,7 @@ var Router5 = (function () {
}

cannotDeactivate = fromStateIds.slice(i).reverse().map(function (id) {
return _this2.activeComponents[id];
return _this.activeComponents[id];
}).filter(function (comp) {
return comp && comp.canDeactivate;
}).some(function (comp) {
Expand All @@ -431,7 +433,7 @@ var Router5 = (function () {

if (!cannotDeactivate) {
this.lastKnownState = toState;
this._invokeListeners(i > 0 ? '^' + fromStateIds[i - 1] : '^', toState, fromState);
this._invokeListeners('^' + (i > 0 ? fromStateIds[i - 1] : ''), toState, fromState);
this._invokeListeners('=' + toState.name, toState, fromState);
this._invokeListeners('*', toState, fromState);
}
Expand Down
14 changes: 8 additions & 6 deletions dist/umd/router5.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,9 @@
* @private
*/
value: function _invokeListeners(name, newState, oldState) {
var _this = this;

if (!this.callbacks[name]) return;
this.callbacks[name].forEach(function (cb) {
cb.call(_this, newState, oldState);
return cb(newState, oldState);
});
}
}, {
Expand Down Expand Up @@ -406,11 +404,15 @@
}, {
key: '_transition',

/**
*
*/

/**
* @private
*/
value: function _transition(toState, fromState) {
var _this2 = this;
var _this = this;

if (!fromState) {
this.lastKnownState = toState;
Expand All @@ -429,7 +431,7 @@
}

cannotDeactivate = fromStateIds.slice(i).reverse().map(function (id) {
return _this2.activeComponents[id];
return _this.activeComponents[id];
}).filter(function (comp) {
return comp && comp.canDeactivate;
}).some(function (comp) {
Expand All @@ -438,7 +440,7 @@

if (!cannotDeactivate) {
this.lastKnownState = toState;
this._invokeListeners(i > 0 ? '^' + fromStateIds[i - 1] : '^', toState, fromState);
this._invokeListeners('^' + (i > 0 ? fromStateIds[i - 1] : ''), toState, fromState);
this._invokeListeners('=' + toState.name, toState, fromState);
this._invokeListeners('*', toState, fromState);
}
Expand Down
7 changes: 2 additions & 5 deletions modules/Router5.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,7 @@ export default class Router5 {
*/
_invokeListeners(name, newState, oldState) {
if (!this.callbacks[name]) return
this.callbacks[name].forEach(cb => {
cb.call(this, newState, oldState)
})
this.callbacks[name].forEach(cb => cb(newState, oldState))
}

/**
Expand Down Expand Up @@ -342,10 +340,9 @@ export default class Router5 {
.filter(comp => comp && comp.canDeactivate)
.some(comp => !comp.canDeactivate(toState, fromState))


if (!cannotDeactivate) {
this.lastKnownState = toState
this._invokeListeners(i > 0 ? '^' + fromStateIds[i - 1] : '^', toState, fromState)
this._invokeListeners('^' + (i > 0 ? fromStateIds[i - 1] : ''), toState, fromState)
this._invokeListeners('=' + toState.name, toState, fromState)
this._invokeListeners('*', toState, fromState)
}
Expand Down

0 comments on commit 1a7246d

Please sign in to comment.