marklagendijk / ui-router.stateHelper

A helper module for AngularUI Router, which allows you to define your states as an object tree.
MIT License
235 stars 40 forks source link

Added nextSibling and previousSibling properties to states #19

Closed corinna000 closed 9 years ago

corinna000 commented 9 years ago

In order to facilitate using the router for applications like wizards, the nextSibling and previousSibling names are added to each state.

This makes it straightforward to go to previous/next states from within the router since the stateHelper keeps an ordered list of child routes.

I also had trouble getting the karma tests to run. I updated gulp-karma and karma-jasmine to current versions.

marklagendijk commented 9 years ago

I'm sorry but I don't think this makes sense for a general solution. The reason for this is that in the most common situation there are no 'next' and 'previous' siblings. This is only the case for situations like wizards. I therefore feel that it is better to create a specific solution when you have to deal with such specific situation. Could you create a pull request for the other two commits?

corinna000 commented 9 years ago

I added a pull request with just the test updates.

I hope you might reconsider having some child traversal functions. Every SPA I've worked on has had a multi-part form sequence. It seems like the responsibility for managing next/previous state should really belong to the state manager and not to an implementing controller or service (that said, I'll be refactoring my wizard service to include a helper that manages this now).

Cheers.

marklagendijk commented 9 years ago

Hmm, it would be ok if this would be a option which would default to false. If you would implement it with the following method signature I would accept it:

/** 
* @param {Object} state - A regular ui.router state object.
* @param {Array} [state.children] - An optional array of child states.
* @param {Boolean} [keepOriginalNames=false] - An optional flag that prevents conversion of names to dot notation if true.
* @param {Object} [options] - An optional options object.
* @param {Boolean} [options.keepOriginalNames=false] An optional flag that prevents conversion of names to dot notation if true.
* @param {Boolean} [options.sibblingTraversal=false] An optional flag that adds `nextSibling` and `previousSibling` properties when enabled
*/
corinna000 commented 9 years ago

Sounds good, I'll work on this. Thanks.