Comments (6)
@marshall007 my thoughts... I'm not super fond of having to export everything, nor adding extra ceremony around resolve. I do like the idea of typing the resolve data for a specific class, although I am not sure about where the typing data would be used.
This is especially true now given that the AoT compiler complains on non-exported anonymous resolveFn.
Here's an alternative approach I've been toying with:
@State()
export class PersonState {
name = 'person',
url = '/people/:personId',
component = Person,
@Resolve({ deps: [PeopleService, Transition] })
person(peopleSvc, transition) {
return peopleSvc.getPerson(transition.params().personId);
}
};
The current problem is that the state is no longer statically analyzable (because component = Person
is effectively handled in the constructor). I've had a couple of conversations with @robwormald about what we would need to support this, and my current hope is that we'll be able to do this eventually.
from core.
@christopherthielen I'd be happy to work on this if I could get your thoughts on the initial proposal. I'm also curious to know whether or not there might be pitfalls associated with this approach.
from core.
I'm definitely a fan of the @Resolve()
decorator and declaring resolve data directly on the state like that. However, I still find having to explicitly declare deps
rather annoying. The key thing I was trying to accomplish in my proposal was a method that takes advantage of the metadata emitted by the Angular compiler to resolve dependencies.
My understanding is that there is currently no way to accomplish this other than implementing a class. I would love to be wrong about that, but unless we can get the @Resolve()
decorator to emit metadata annotations for its injected dependencies, I think a Resolve<T>
interface is still the cleaner solution.
@christopherthielen thoughts?
from core.
@marshall007 basically resolve function is a small piece of code (use a function is fairly enough), I prefer explicitly declare deps
rather than defining another service which I need to define explicitly in state
declaration and @NgModel
from core.
In v5 it appears there will be an emphasis on declaring states as classes (as @christopherthielen proposed above). Instead of a new Resolve<T>
interface I was suggesting, what do you guys think about injecting dependencies in the state definition's constructor itself? In doing so, would we still be able provide a mechanism for injecting resolved dependencies from a parent state too (presumably using @Inject(<token>)
)?
@State("person")
export class PersonState {
url = '/people/:personId',
component = Person,
constructor(private peopleSvc: PeopleService, private transition: Transition) { }
@Resolve()
person() {
return this.peopleSvc.getPerson(this.transition.params().personId);
}
};
It would be really great if the Angular team exposed a decorator or some other mechanism for telling the compiler to preserve parameter metadata on an arbitrary function. That way we could just do:
@Resolve()
person(peopleSvc: PeopleService, transition: Transition) {
return peopleSvc.getPerson(transition.params().personId);
}
The current problem is that the state is no longer statically analyzable (because
component = Person
is effectively handled in the constructor).
Have you guys had any further communication with the Angular team on this point? Is the discussion around getting them to emit type metadata for generics so we can do something like class PersonState implements StateDeclaration<Person>
or what is the plan there?
from core.
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs.
This does not mean that the issue is invalid. Valid issues
may be reopened.
Thank you for your contributions.
from core.
Related Issues (20)
- @uirouter/react 0.8.9 not finding UIRouter HOT 1
- Any plan for Svelte 3? HOT 7
- Can't compile angular 8 under typescript "~3.5.3" HOT 3
- Version 6.0.2 breaks using ui-router core on Node.js without a browser HOT 1
- Can't bootstrap a hybrid application in Angular 8 due to commonservices being undefined HOT 6
- string parameters are url encoding issue HOT 5
- is AOT supported? HOT 1
- Ability to set defaultHrefOpts globally HOT 3
- Ugrading to uirouter1.x and installed ui-router-core and ui-router-angularjs ,doesnt support legacy code base HOT 1
- `inherit` is documented as having the wrong default value HOT 1
- Cannot read property 'when' of undefined HOT 19
- Child states their childs, show the parent component HOT 3
- Set uiOptions.reload of [uiSref] to a future load state name lead to error at first load HOT 1
- license issue HOT 1
- How to lazy load with chunks HOT 1
- Support Ivy partial compilation HOT 10
- `ParamDeclaration.inherit = false` is ignored by `$state.href()`
- Issue with StateParams HOT 4
- error TS1086: An accessor cannot be declared in an ambient context (v6.1.1) HOT 6
- explicit file path in `import` and `export` statements in ES modules for better web-browser support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from core.