Skip to content

Commit

Permalink
feat: add isActive(name, params) function
Browse files Browse the repository at this point in the history
  • Loading branch information
troch committed Jul 7, 2015
1 parent faf9e3d commit 26303da
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "router5",
"version": "0.1.0-rc.3",
"version": "0.1.0-rc.4",
"homepage": "http://router5.github.io",
"authors": [
"Thomas Roch <thomas.c.roch@gmail.com>"
Expand Down
14 changes: 14 additions & 0 deletions dist/browser/router5.js
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,20 @@ var Router5 = (function () {
// return window.history.state
;
}
}, {
key: 'isActive',

/**
* Whether or not the given route name with specified params is active.
* @param {String} name The route name
* @param {Object} [params={}] The route parameters
* @return {Boolean} Whether nor not the route is active
*/
value: function isActive(name) {
var params = arguments[1] === undefined ? {} : arguments[1];

return this.areStatesEqual(makeState(name, params), this.getState());
}
}, {
key: 'getWindowPath',

Expand Down
2 changes: 1 addition & 1 deletion dist/browser/router5.min.js

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions dist/commonjs/router5.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,20 @@ var Router5 = (function () {
// return window.history.state
;
}
}, {
key: 'isActive',

/**
* Whether or not the given route name with specified params is active.
* @param {String} name The route name
* @param {Object} [params={}] The route parameters
* @return {Boolean} Whether nor not the route is active
*/
value: function isActive(name) {
var params = arguments[1] === undefined ? {} : arguments[1];

return this.areStatesEqual(makeState(name, params), this.getState());
}
}, {
key: 'getWindowPath',

Expand Down
14 changes: 14 additions & 0 deletions dist/umd/router5.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,20 @@
// return window.history.state
;
}
}, {
key: 'isActive',

/**
* Whether or not the given route name with specified params is active.
* @param {String} name The route name
* @param {Object} [params={}] The route parameters
* @return {Boolean} Whether nor not the route is active
*/
value: function isActive(name) {
var params = arguments[1] === undefined ? {} : arguments[1];

return this.areStatesEqual(makeState(name, params), this.getState());
}
}, {
key: 'getWindowPath',

Expand Down
10 changes: 10 additions & 0 deletions modules/Router5.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,16 @@ export default class Router5 {
// return window.history.state
}

/**
* Whether or not the given route name with specified params is active.
* @param {String} name The route name
* @param {Object} [params={}] The route parameters
* @return {Boolean} Whether nor not the route is active
*/
isActive(name, params = {}) {
return this.areStatesEqual(makeState(name, params), this.getState())
}

/**
* @private
*/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "router5",
"version": "0.1.0-rc.3",
"version": "0.1.0-rc.4",
"description": "An HTML5 router, based on route-node and path-parser",
"main": "dist/commonjs/index.js",
"scripts": {
Expand Down
11 changes: 11 additions & 0 deletions tests/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,16 @@ describe('router5', function () {
router.registerComponent('users.view', {});
expect(console.warn).toHaveBeenCalled();
});

it('should tell if a route is active or not', function () {
router.navigate('users.view', {id: 1});
expect(router.isActive('users.view', {id: 1})).toBe(true);
expect(router.isActive('users.view', {id: 2})).toBe(false);
expect(router.isActive('users.view')).toBe(false);

router.navigate('users');
expect(router.isActive('users')).toBe(true);
expect(router.isActive('users', {})).toBe(true);
});
});

0 comments on commit 26303da

Please sign in to comment.