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

Exit/Reset a Sticky State #5

Closed
dcarabott opened this issue Mar 10, 2017 · 1 comment
Closed

Exit/Reset a Sticky State #5

dcarabott opened this issue Mar 10, 2017 · 1 comment
Labels

Comments

@dcarabott
Copy link

Having an issue when exiting a sticky state. Currently the API offers two options to exit a Sticky State (correct me if I'm wrong).

First Option:

Setting an exitState property when redirecting to another state.

Example:
this.router.stateService.go('app.new-state', {}, {exitSticky: 'app.sticky-state'})

Second Option

Using this.router.getPlugin('stickystates').exitSticky() to exit all inactive sticky states. This option enables you to exit a specific state as well.

If that's all correct, this means that to exit a sticky state it has to first be inactive, which makes sense. What this also means is that in order to exit a sticky state you have to redirect to another state even if that sticky state is already inactive. This case creates a problem.

Test Scenario
Let's say we have 2 states: app.normal-state and app.sticky-state, which as the name implies the app.sticky-state is a sticky: true state.

The user is currently on app.sticky-state and there's a close button which should take him to app.normal-state. This scenario requires that after closing, the inactive sticky state should be exited.

If the first option is used (this.router.stateService.go('app.normal-state', {}, {exitSticky: 'app.sticky-state'})) it won't work since app.sticky-state is not inactive.

If the second option is used (this.router.getPlugin('stickystates').exitSticky()) by having some timeout after the state successfully transitions, the following API code will trigger:

  exitSticky(states?: any) {
    let $state = this.router.stateService;
    if (states === undefined) states = this._inactives.map(node => node.state.name);
    if (isString(states)) states = [states];

    return $state.go($state.current, {}, {
      inherit: true,
      exitSticky: states
    });
  }

This code will not work as the $state.go will redirect to the current state which will not have any effect. A reload: true would trigger an effect.

The problem here is that in order to exit a sticky state, one has to transition to another state. This is not always the case. It would be best to have an option which just exits inactive sticky states without transitioning to a new state. On the previous UIRouterExtras project this was possible using this.$stickyState.reset('*').

@christopherthielen
Copy link
Member

The code previously didn't allow exitSticky for a state that is currently active, but is scheduled to be inactivated during the new transition. This should be fixed now.

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