Skip to content

Commit

Permalink
Version 1.2.0
Browse files Browse the repository at this point in the history
- Deprecated `setNestedState` in favor of `state`, to match `$stateProvider`.
- Added support for chaining `state` calls.
- Updated dependencies
  • Loading branch information
Mark Lagendijk committed Oct 30, 2014
1 parent 2ee5ab9 commit fad3d6d
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 54 deletions.
70 changes: 39 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,52 @@ A helper module for AngularUI Router, which allows you to define your states as

## Usage
``` javascript
angular.module('myApp', ['ui.router', 'ui.router.stateHelper'])
.config(function(stateHelperProvider){
stateHelperProvider.setNestedState({
name: 'root',
templateUrl: 'root.html',
children: [
{
name: 'contacts',
templateUrl: 'contacts.html',
children: [
{
name: 'list',
templateUrl: 'contacts.list.html'
}
]
},
{
name: 'products',
templateUrl: 'products.html',
children: [
{
name: 'list',
templateUrl: 'products.list.html'
}
]
}
]
});
});
angular.module('myApp', [ 'ui.router', 'ui.router.stateHelper' ])
.config(function(stateHelperProvider){
stateHelperProvider
.state({
name: 'root',
templateUrl: 'root.html',
children: [
{
name: 'contacts',
templateUrl: 'contacts.html',
children: [
{
name: 'list',
templateUrl: 'contacts.list.html'
}
]
},
{
name: 'products',
templateUrl: 'products.html',
children: [
{
name: 'list',
templateUrl: 'products.list.html'
}
]
}
]
})
.state({
name: 'rootSibling',
templateUrl: 'rootSibling.html'
});
});
```

## Options
### Dot notation name conversion
By default, all state names are converted to use ui-router's dot notation (e.g. `parentStateName.childStateName`).
This can be disabled by calling `.setNestedState()` with an optional second parameter of `true`.
This can be disabled by calling `.state()` with an optional second parameter of `true`.
For example:

``` javascript
angular.module('myApp', ['ui.router', 'ui.router.stateHelper'])
.config(function(stateHelperProvider){
stateHelperProvider.setNestedState({
stateHelperProvider.state({
name: 'root',
templateUrl: 'root.html',
children: [
Expand All @@ -60,3 +65,6 @@ angular.module('myApp', ['ui.router', 'ui.router.stateHelper'])
}, true);
});
```

## Name change
Before 1.2.0 `.setNestedState` was used instead of `.state`. In 1.2.0 `setNestedState` was deprecated in favour of `.state`, and chaining was added. This makes it easier to switch between `$stateProvider` and `stateHelperProvider`.
8 changes: 4 additions & 4 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "angular-ui-router.stateHelper",
"main": "statehelper.js",
"version": "1.1.0",
"version": "1.2.0",
"homepage": "https://github.com/marklagendijk/ui-router.stateHelper",
"authors": [
"Mark Lagendijk <mark@lagendijk.info>"
Expand All @@ -27,10 +27,10 @@
"config"
],
"dependencies": {
"angular": "~1.2.13",
"angular-ui-router": "~0.2.7"
"angular": ">=1.2.0",
"angular-ui-router": "~0.2.11"
},
"devDependencies": {
"angular-mocks": "~1.2.8"
"angular-mocks": ">=1.2.8"
}
}
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var gulp = require("gulp");
var ngmin = require('gulp-ngmin');
var ngmin = require('gulp-ng-annotate');
var uglify = require("gulp-uglify");
var rename = require("gulp-rename");
var karma = require("gulp-karma");
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"dependencies": {},
"devDependencies": {
"karma": "~0.11.9",
"gulp": "~3.8.0",
"gulp-karma": "0.0.1",
"gulp-ng-annotate": "^0.3.3",
"gulp-rename": "~0.2.1",
"gulp-uglify": "~0.1.0",
"karma": "^0.12.24",
"karma-chrome-launcher": "~0.1.2",
"karma-jasmine": "~0.1.5",
"karma-firefox-launcher": "~0.1.3",
"karma-jasmine": "~0.1.5",
"karma-phantomjs-launcher": "~0.1.1",
"karma-requirejs": "~0.2.1",
"karma-script-launcher": "~0.1.0",
"gulp": "~3.3.0",
"gulp-uglify": "~0.1.0",
"gulp-karma": "0.0.1",
"gulp-rename": "~0.2.1",
"gulp-ngmin": "^0.1.2"
"karma-script-launcher": "~0.1.0"
}
}
13 changes: 8 additions & 5 deletions statehelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @author Mark Lagendijk <mark@lagendijk.info>
* @license MIT
*/
angular.module('ui.router.stateHelper', ['ui.router'])
angular.module('ui.router.stateHelper', [ 'ui.router' ])
.provider('stateHelper', function($stateProvider){
var self = this;

Expand All @@ -19,8 +19,8 @@ angular.module('ui.router.stateHelper', ['ui.router'])
* @param {Array} [state.children] - An optional array of child states.
* @param {Boolean} keepOriginalNames - An optional flag that prevents conversion of names to dot notation if true.
*/
this.setNestedState = function(state, keepOriginalNames){
if (!keepOriginalNames){
this.state = function(state, keepOriginalNames){
if(!keepOriginalNames){
fixStateName(state);
}
$stateProvider.state(state);
Expand All @@ -31,8 +31,12 @@ angular.module('ui.router.stateHelper', ['ui.router'])
self.setNestedState(childState, keepOriginalNames);
});
}

return self;
};

this.setNestedState = this.state;

self.$get = angular.noop;

/**
Expand All @@ -44,5 +48,4 @@ angular.module('ui.router.stateHelper', ['ui.router'])
state.name = state.parent.name + '.' + state.name;
}
}
})
;
});
2 changes: 1 addition & 1 deletion statehelper.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 15 additions & 4 deletions test/statehelperSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('ui-router.stateHelper', function(){
spyOn($stateProvider, 'state');
}));

describe('.setNestedState', function(){
describe('.state', function(){
beforeEach(inject(function(){
expectedState = {
name: 'root',
Expand All @@ -49,7 +49,7 @@ describe('ui-router.stateHelper', function(){
]
};

stateHelperProvider.setNestedState(rootState);
stateHelperProvider.state(rootState);
}));

it('should set each state', function(){
Expand All @@ -67,9 +67,13 @@ describe('ui-router.stateHelper', function(){

expect($stateProvider.state.argsForCall[0][0]).toEqual(expectedState);
});

it('should return itself to support chaining', function(){
expect($stateProvider.state(rootState)).toBe($stateProvider);
})
});

describe('.setNestedState with keepOriginalNames set to true', function(){
describe('.state with keepOriginalNames set to true', function(){
beforeEach(inject(function(){
expectedState = {
name: 'root',
Expand All @@ -89,7 +93,7 @@ describe('ui-router.stateHelper', function(){
]
};

stateHelperProvider.setNestedState(rootState, true);
stateHelperProvider.state(rootState, true);
}));

it('should not convert names to dot notation, set parent references', function(){
Expand All @@ -104,6 +108,13 @@ describe('ui-router.stateHelper', function(){
expect($stateProvider.state.argsForCall[0][0]).toEqual(expectedState);
});
});

describe('.setNestedState', function(){
it('should support .setNestedState as legacy name', function(){
stateHelperProvider.setNestedState(rootState);
expect($stateProvider.state.callCount).toBe(4);
});
});
});


Expand Down

0 comments on commit fad3d6d

Please sign in to comment.