Skip to content

RFC: $transition$ injectable promise #1257

@christopherthielen

Description

@christopherthielen

I've been working on the "transition service" idea that's been tossed around here. See this commit in ui-router-extras: christopherthielen/ui-router-extras@92c4f81

So far, I have implemented and tested

  • $transition$: an injectable object which contains:
    • the to state/params
    • the from state/params
    • a promise which wraps the $state.transitionTo() promise
  • $transitionStart: a new event, fired in response to $stateChangeStart which exposes the $transition$ object/promise
  • $transitionSuccess and $transitionError Mirrors $stateChangeSuccess/Error, but are broadcasted based on the promise. I'm not sold on these, they seem perhaps unnecessary, but I put them in because it was ridiculously easy to do so.

$transition$

The $transition$ object contains the details of the current transition, to: { state: toState, params: toParams} and from: { state: fromState, params: fromParams } }. It also has promise which is resolved when the promise returned by $state.transitionTo() is resolved.

$transition is injectable as long as the transition is currently in process. This means it can be injected into onEnter/onExit/controller functions.

$transitionStart

The $transitionStart event fires in response to $stateChangeStart. This event exposes $transition to interested parties. Since $transitionStart exposes $transition$, it allows interested parties to listen for transitions, then process them using promises, which was impossible using $stateChangeStart.

benefits

  • Listen for state changes, respond using promises. When listening for $stateChangeStart/Success/Error, there is a separation between the starting event and the terminating event. One also has to listen for both Success and Error events to connect the dots.
  • Inject current transition into code invoked while the transition is pending. Currently, onEnter/Exit/controller don't know why they are being invoked. For example, the onEnter doesn't know if the destination state is that specific state, or some substate.
  • ??? other things?
  • Profit!!!

closes

I believe this change would address the following:

#1169
#1182
#1153
#1151
#1112
#1100
#1085
#1016
#575
#238
#23

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions