-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
Hello,
Currently, we can define onEnter
and onExit
on our states. We can also get a global event for $stateChangeSuccess
, but the state itself can't register for such an event.
I'd like to send a PR that would include onSuccess
and onError
to a state, so that the state can do something at that time.
The use case that I want to support is outlined in the StackOverflow question dealing with polymorphic views. Basically, I'd like to create a specialized state for polymorphic view rendering.
I'd like to do this upon success. For instance, if the state received the onSuccess
callback, I could do this: $state.$go('.male')
to navigate to the sub-state. I can't do this in onEnter because the state hasn't actually transitioned. In other words, that one won't work because $state.current
is the exiting state. Going to an absolute state at this point results in a complete state reload, therefore we get into an endless transitioning loop.
By adding the onSuccess
callback, I believe that I am extending the behavior to be generic and it falls within the philosophy of the module. I'd also add onError
for completeness.
Thoughts? Am I thinking about this wrong? If not, are there any things that I need to consider before jumping into it? (unit tests, of course) I have prototyped the concept locally and it does solve my problem.