Skip to content

adds statechangecancel event #1090

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

Closed
wants to merge 2 commits into from
Closed

adds statechangecancel event #1090

wants to merge 2 commits into from

Conversation

elmerbulthuis
Copy link

After preventDefault is fired in stateChangeStart, a stageChangeCancel event will be launched.

@adamschwartz
Copy link

👍

@rpocklin
Copy link
Contributor

Any reason this hasn't landed yet? I need this and am working around it for the time being.

@christopherthielen christopherthielen self-assigned this Mar 26, 2015
@christopherthielen
Copy link
Contributor

While the state events are probably going to be deprecated in favor of transition callbacks in 1.0, I think this is a reasonable thing to include in 0.2.x, for those who can't (or won't want to) update to 1.0. @nateabele what say you?

@nateabele
Copy link
Contributor

I was always kind of against this because you're basically notifying your own code of what it's doing. I'm willing to be persuaded on this point though.

@rpocklin
Copy link
Contributor

If you visit http://rpocklin.github.io/angular-ui-view-spinner/example/index.html and click some links you can see it's a directive that shows a loading spinner while the resolves are processed. There are 2 ways (AFAIK) that route state transitions in ui-router can fail:

  • A resolve for the target state throws an exception (or returns a falsy value)
  • In a $stateChangeStart event handler, you can do event.preventDefault();

In the first case, a $stateChangeError is triggered. In the second, though, there is no event triggered such as $stateChangeCancel which means the loading spinner has no hook to stop.

I can manually trigger a $stateChangeError event for the second case, but IMO this is a prime candidate for a different event, especially since it's the user or system deciding to cancel the state change, and not because a dependent resolve has failed.

@nateabele if you are writing both sets of code within the same codebase, you are right you have control over the interactions. But what if you are combining two third party directives which don't directly talk to each other? Eg. the above one and one which pops up a window to prevent unsaved changes in a state being lost? (Eg. https://github.com/facultymatt/angular-unsavedChanges)

@nateabele
Copy link
Contributor

That's fair. Squash & fix the commit message per the contributor guidelines and we'll merge it.

@rpocklin
Copy link
Contributor

Done - see #1844 as original PR wasn't mine.

@nateabele
Copy link
Contributor

Implemented in #1844.

@nateabele nateabele closed this Mar 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants