-
Notifications
You must be signed in to change notification settings - Fork 3k
Custom UrlMatcher types cannot be decoded asynchronously #1634
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
Comments
I think that example is jumping the gun a bit. I haven't worked this through to full resolution, but you could of course return a promise from your custom type, which you could then resolve. This, at least, encapsulates the async code into the custom type, e.g., http://plnkr.co/edit/4HvP0zCiQOHKvPwY781o?p=preview
You could even register all state parameters as resolves using a decorator and skip the boilerplate resolve declarations: http://plnkr.co/edit/3MGHlZjR0zBPhQxky0sZ?p=preview
Unfortunately this means you are passing around a promise as the state param, not a typed user object, which is not ideal. |
Interesting. It seems like the logical thing to do would be to process |
Yeah, I've been tossing that idea around (add all params to resolve), specifically for this use case, and also for ease-of-use (injecting a param directly, if you want, as opposed to |
Agh. I had a long reply typed out, and lost it. My thought is basically that we should use the infrastructure that we already have (resolve) for cases where we want to directly inject things into controllers via DI. I've shied away from extensively using revolve in my own code, because it tends to be brittle, and leads to a lot of duplication and repetition if I want to use a controller in more than one place. Splitting the logic between the controller and the state definition isn't DRY, and breaks encapsulation. It also makes it awkward/difficult to instantiate controllers outside of a state, because Angular's DI isn't particularly forgiving. Typed URL parameters seem like they could be a huge step in the right direction, as they allow me to consolidate a lot of my code, and significantly streamline the currently-awkward process of passing data between states (or inheriting things asynchronously from parent states). It also provides a graceful fallback for controllers that could potentially be instantiated without a full set of stateParams or resolves (letting us do something like However, I'm still left with the problem that this encourages me to write controllers that don't know how to load all of the data that they need to run. If I decide that I want to use the same controller in a state and a directive, it would be nice if ui-router defined an idiomatic way to "fill in" missing data that might have otherwise been provided via a resolve or state parameter. Basically, I want to be able to write properly-encapsulated controllers, but also take advantage of the nice things that resolve and state parameters provide, especially so that I can deduplicate data loading in nested states. |
Tangentially, this is starting to sound like a good case for adding hooks for ui-router to interact with a more comprehensive data-persistence layer like |
I think that this is still a valid issue. Resolves are a powerful feature, but I think they need to be used sparingly. Decoding URL params into objects (possibly via an AJAX call, or a call to some other persistence layer) seems like it could potentially be a much more maintainable solution. |
Yeah, we can leave this open as a potential design issue. I'm not sure what injecting individual parameters would look like, but accessing unwrapped async values without additional ceremony would definitely be handy. |
I think this will be possible using transition hooks. A hook can add resolves on the fly. The hook could inspect the state params and create a resolve that fetches the data based on the param. |
(I don't think this belongs in the params layer, by the way) |
One reason for it to still belong in the params layer is One obvious pitfall is how to decide when the state is finally transitioned to/resolved, or whether it is OK for the user to not be known right away and what to show in the UI in the meantime. |
This issue has been automatically marked as stale because it has not had This does not mean that the issue is invalid. Valid issues Thank you for your contributions. |
The example contained within the documentation for custom
UrlMatcherFactory
types implies that I should be able to implement a custom type that resolves some data from an AJAX call:After browsing the code, it doesn't appear that there is any sort of support for asynchronously decoding custom URL parameters.
resolve
.It sounds like the new
transitionProvider
magic explained in #1399 might be a prerequisite to getting this to work. Thoughts?The text was updated successfully, but these errors were encountered: