Skip to content

Commit

Permalink
chore: v0.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
troch committed Jul 29, 2015
1 parent a79ac22 commit c598ae5
Show file tree
Hide file tree
Showing 9 changed files with 366 additions and 64 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,13 @@
<a name="0.4.2"></a>
## 0.4.2 (2015-07-29)


### Features

* add transition hooks (onTransitionStart, onTransitionCancel, onTransitionError) ([d166cb0](https://github.com/router5/router5/commit/d166cb0))



<a name="0.4.1"></a>
## 0.4.1 (2015-07-29)

Expand Down
2 changes: 1 addition & 1 deletion bower.json
@@ -1,6 +1,6 @@
{
"name": "router5",
"version": "0.4.1",
"version": "0.4.2",
"homepage": "http://router5.github.io",
"authors": [
"Thomas Roch <thomas.c.roch@gmail.com>"
Expand Down
103 changes: 88 additions & 15 deletions dist/amd/router5.js
@@ -1,6 +1,6 @@
/**
* @license
* @version 0.4.1
* @version 0.4.2
* The MIT License (MIT)
*
* Copyright (c) 2015 Thomas Roch
Expand Down Expand Up @@ -732,17 +732,6 @@ define('router5', [], function () {
this.rootNode.add(routes);
return this;
}
}, {
key: 'onTransition',

/**
* Set a transition middleware function
* @param {Function} fn The middleware function
*/
value: function onTransition(fn) {
this._onTr = fn;
return this;
}
}, {
key: 'addNode',

Expand Down Expand Up @@ -781,6 +770,17 @@ define('router5', [], function () {
}
});
}
}, {
key: 'onTransition',

/**
* Set a transition middleware function
* @param {Function} fn The middleware function
*/
value: function onTransition(fn) {
this._onTr = fn;
return this;
}
}, {
key: 'start',

Expand Down Expand Up @@ -944,9 +944,13 @@ define('router5', [], function () {
/**
* @private
*/
value: function _invokeListeners(name, newState, oldState) {
value: function _invokeListeners(name) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}

(this._cbs[name] || []).forEach(function (cb) {
return cb(newState, oldState);
return cb.apply(undefined, args);
});
}
}, {
Expand All @@ -957,7 +961,7 @@ define('router5', [], function () {
*/
value: function _addListener(name, cb, replace) {
var normalizedName = name.replace(/^(\*|\^|=)/, '');
if (normalizedName) {
if (normalizedName && !/^\$/.test(name)) {
var segments = this.rootNode.getSegmentsByName(normalizedName);
if (!segments) console.warn('No route found for ' + normalizedName + ', listener might never be called!');
}
Expand Down Expand Up @@ -1048,6 +1052,72 @@ define('router5', [], function () {
value: function removeRouteListener(name, cb) {
return this._removeListener('=' + name, cb);
}
}, {
key: 'onTransitionStart',

/**
* Add a transition start callback
* @param {Function} cb The callback
* @return {Router5} The router instance
*/
value: function onTransitionStart(cb) {
return this._addListener('$start', cb);
}
}, {
key: 'offTransitionStart',

/**
* Remove a transition start callback
* @param {Function} cb The callback
* @return {Router5} The router instance
*/
value: function offTransitionStart(cb) {
return this._removeListener('$start', cb);
}
}, {
key: 'onTransitionCancel',

/**
* Add a transition cancel callback
* @param {Function} cb The callback
* @return {Router5} The router instance
*/
value: function onTransitionCancel(cb) {
return this._addListener('$cancel', cb);
}
}, {
key: 'offTransitionCancel',

/**
* Remove a transition cancel callback
* @param {Function} cb The callback
* @return {Router5} The router instance
*/
value: function offTransitionCancel(cb) {
return this._removeListener('$cancel', cb);
}
}, {
key: 'onTransitionError',

/**
* Add a transition error callback
* @param {Function} cb The callback
* @return {Router5} The router instance
*/
value: function onTransitionError(cb) {
return this._addListener('$error', cb);
}
}, {
key: 'offTransitionError',

/**
* Remove a transition error callback
* @param {Function} cb The callback
* @return {Router5} The router instance
*/
value: function offTransitionError(cb) {
return this._removeListener('$error', cb);
}
}, {
key: 'registerComponent',

Expand Down Expand Up @@ -1144,11 +1214,14 @@ define('router5', [], function () {

// Cancel current transition
if (this._tr) this._tr();
this._invokeListeners('$start', toState, fromState);

var tr = transition(this, toState, fromState, function (err) {
_this4._tr = null;

if (err) {
if (err === constants.TRANSITION_CANCELLED) _this4._invokeListeners('$cancel', toState, fromState);else _this4._invokeListeners('$error', toState, fromState, err);

if (done) done(err);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions dist/amd/router5.min.js

Large diffs are not rendered by default.

103 changes: 88 additions & 15 deletions dist/browser/router5.js
@@ -1,6 +1,6 @@
/**
* @license
* @version 0.4.1
* @version 0.4.2
* The MIT License (MIT)
*
* Copyright (c) 2015 Thomas Roch
Expand Down Expand Up @@ -732,17 +732,6 @@
this.rootNode.add(routes);
return this;
}
}, {
key: 'onTransition',

/**
* Set a transition middleware function
* @param {Function} fn The middleware function
*/
value: function onTransition(fn) {
this._onTr = fn;
return this;
}
}, {
key: 'addNode',

Expand Down Expand Up @@ -781,6 +770,17 @@
}
});
}
}, {
key: 'onTransition',

/**
* Set a transition middleware function
* @param {Function} fn The middleware function
*/
value: function onTransition(fn) {
this._onTr = fn;
return this;
}
}, {
key: 'start',

Expand Down Expand Up @@ -944,9 +944,13 @@
/**
* @private
*/
value: function _invokeListeners(name, newState, oldState) {
value: function _invokeListeners(name) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}

(this._cbs[name] || []).forEach(function (cb) {
return cb(newState, oldState);
return cb.apply(undefined, args);
});
}
}, {
Expand All @@ -957,7 +961,7 @@
*/
value: function _addListener(name, cb, replace) {
var normalizedName = name.replace(/^(\*|\^|=)/, '');
if (normalizedName) {
if (normalizedName && !/^\$/.test(name)) {
var segments = this.rootNode.getSegmentsByName(normalizedName);
if (!segments) console.warn('No route found for ' + normalizedName + ', listener might never be called!');
}
Expand Down Expand Up @@ -1048,6 +1052,72 @@
value: function removeRouteListener(name, cb) {
return this._removeListener('=' + name, cb);
}
}, {
key: 'onTransitionStart',

/**
* Add a transition start callback
* @param {Function} cb The callback
* @return {Router5} The router instance
*/
value: function onTransitionStart(cb) {
return this._addListener('$start', cb);
}
}, {
key: 'offTransitionStart',

/**
* Remove a transition start callback
* @param {Function} cb The callback
* @return {Router5} The router instance
*/
value: function offTransitionStart(cb) {
return this._removeListener('$start', cb);
}
}, {
key: 'onTransitionCancel',

/**
* Add a transition cancel callback
* @param {Function} cb The callback
* @return {Router5} The router instance
*/
value: function onTransitionCancel(cb) {
return this._addListener('$cancel', cb);
}
}, {
key: 'offTransitionCancel',

/**
* Remove a transition cancel callback
* @param {Function} cb The callback
* @return {Router5} The router instance
*/
value: function offTransitionCancel(cb) {
return this._removeListener('$cancel', cb);
}
}, {
key: 'onTransitionError',

/**
* Add a transition error callback
* @param {Function} cb The callback
* @return {Router5} The router instance
*/
value: function onTransitionError(cb) {
return this._addListener('$error', cb);
}
}, {
key: 'offTransitionError',

/**
* Remove a transition error callback
* @param {Function} cb The callback
* @return {Router5} The router instance
*/
value: function offTransitionError(cb) {
return this._removeListener('$error', cb);
}
}, {
key: 'registerComponent',

Expand Down Expand Up @@ -1144,11 +1214,14 @@

// Cancel current transition
if (this._tr) this._tr();
this._invokeListeners('$start', toState, fromState);

var tr = transition(this, toState, fromState, function (err) {
_this4._tr = null;

if (err) {
if (err === constants.TRANSITION_CANCELLED) _this4._invokeListeners('$cancel', toState, fromState);else _this4._invokeListeners('$error', toState, fromState, err);

if (done) done(err);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions dist/browser/router5.min.js

Large diffs are not rendered by default.

0 comments on commit c598ae5

Please sign in to comment.