Giter Site home page Giter Site logo

Comments (6)

christopherthielen avatar christopherthielen commented on May 7, 2024 2

@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.

marshall007 avatar marshall007 commented on May 7, 2024

@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.

marshall007 avatar marshall007 commented on May 7, 2024

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.

aitboudad avatar aitboudad commented on May 7, 2024

@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.

marshall007 avatar marshall007 commented on May 7, 2024

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.

stale avatar stale commented on May 7, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.