Skip to content

It should be possible to disable promise-unwrapping for resolves #2691

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
jonrimmer opened this issue Apr 12, 2016 · 4 comments
Closed

It should be possible to disable promise-unwrapping for resolves #2691

jonrimmer opened this issue Apr 12, 2016 · 4 comments

Comments

@jonrimmer
Copy link

I've been trying the 1.0-alpha with ng1. I'm disappointed that there still seems to be no way to disable promise-unwrapping / entry-delay for resolves.

As I understand it, resolves address two separate concerns:

  1. Allowing two or more states to share a common dependency, such as the result of an asynchronous request, that is loaded whenever one of them is entered.
  2. Allowing states to delay entry until all their dependencies are ready, and abort the transition if any of them errors.

I don't understand why ui-router conflates these two things without any way to prevent it doing so. If I want to handle progressive-rendering myself in my components, but still have ui-router supply their dependencies, I should be able to tell ui-router to give me the un-unwrapped promises for the resolved values without delaying entry.

@nateabele
Copy link
Contributor

A while ago we started making the under-the-hood changes necessary to allow templates to be rendered up-front while delaying controller instantiation, so that we could provide some sugar for progressive rendering, but maybe this is a better approach...

Seems like it should be implementable with a new resolve policy. Check out ResolveContext if you're interested in submitting a PR.

@christopherthielen
Copy link
Contributor

This seems like a reasonable request and should be pretty easy to achieve.

Resolve Policy defines how the resolve blocking code works. EAGER resolves block the transition during onStart(); LAZY resolves block the transition during each state's onEnter(). JIT resolves don't block the transition at all, unless they are injected into another resolve or a controller.

I'm planning on removing JIT resolves because I couldn't come up with a compelling use case that the regular transition hooks couldn't already solve.

We could implement a NONBLOCKING policy. Maybe NONBLOCKING resolves are fetched when the states are entered, but don't block the transition. Anywhere we inject a NONBLOCKING Resolvable we would inject the promise instead.

The touch points for this are in ResolveContext.invokeLater, ResolveContext.invokeNow and in viewDirective where we put the resolve data on scope[resolveAs]

@christopherthielen
Copy link
Contributor

Implemented as NOWAIT

.state('foo' {
  resolve: { data: ($timeout) => $timeout(1000).then(() => 'data') },
  resolvePolicy: { async: 'NOWAIT' }
});

@christopherthielen
Copy link
Contributor

Hmm this should be closed I guess

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

No branches or pull requests

3 participants