Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transition hook criteria issue #3119

Closed
cadilhac opened this issue Oct 31, 2016 · 8 comments
Closed

Transition hook criteria issue #3119

cadilhac opened this issue Oct 31, 2016 · 8 comments
Labels

Comments

@cadilhac
Copy link

cadilhac commented Oct 31, 2016

I have encountered a problem when using $transitions and declaring the to and from parameters.
(using 1.0 beta 3, NG1)

Here is the states tree:
A -> B
B -> C
B -> D

When I use to:C, from:D, it works well.
If I replace by to:B.C, from:D it doesn't work anymore.
Same issue with to:B.**, from:D or if I modify from:D with same kind of alternatives.

Note: in your doc about globs, for the exact match, you could add for glob 'A' if it matches or not 'B.A' i.e. if ancestors have to be specified or if the glob tries to match a leaf of the tree or a group of segments at the leaf of the tree.

@christopherthielen
Copy link
Contributor

christopherthielen commented Nov 2, 2016

Sorry, I don't really understand what you're trying to explain here. Perhaps it would help if you added some code, not just narrative.

Are your states named A, B, C, and D,
or A, A.B, A.B.C, and A.B.D?

Glob matches are based only on the name of the state, not on their position in the tree.

@cadilhac
Copy link
Author

cadilhac commented Nov 2, 2016

Yes the states are A, B, C and D. The arrows help represent the tree. So C is the child of B and I use the parent property in code to indicate parents. Since C is the child of B, I guess it is internally represented as B.C.

@cadilhac
Copy link
Author

cadilhac commented Nov 3, 2016

Glob matches are based only on the name of the state, not on their position in the tree.

@christopherthielen Are you saying that globs with the dot notation only work if I define state names with the exact same dot notation? What if I use the parent property when defining states? Can't I use 'B.**' for any B descendant?

@christopherthielen
Copy link
Contributor

Yes, that is a limitation of working with globs: the only match on the name of the state.

You can work around this by creating your own helper predicate function. The predicate function should take a state object as a parameter and return true if the condition matches.

The internal state object representation has an includes map that you can leverage.

function isChildOf(parentStateName) {
  return function(state) {
    return state.$$state().includes(parentStateName);
  }
}

then:

$transitions.onStart({ to: isChildOf('B') }, ...);

or inline:

$transitions.onStart({ to: (state) => state.$$state().includes['B'] }, ...);

@cadilhac
Copy link
Author

cadilhac commented Nov 3, 2016

Yes, that is a limitation of working with globs: the only match on the name of the state.

It's a pity. It would have been so intuitive.

I tried to use $$state in my 'to' function, but it seems to be non existent on the state object...

@christopherthielen
Copy link
Contributor

I forget which object is provided… the state definition, or the internal state object.

Try this one:

(state) => state.includes['B']

@cadilhac
Copy link
Author

cadilhac commented Nov 8, 2016

Ah, this works. Thanks.

@christopherthielen
Copy link
Contributor

I'm closing this issue in favor of tracking it at the core repository
ui-router/core#5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants