Giter Site home page Giter Site logo

Comments (5)

abdulhaq-e avatar abdulhaq-e commented on August 26, 2024 3

That will be considered in the next version. Right now the models are weakly typed. Decorating a model just like angular2-jsonapi would be great. A new version of ngrx tools are being released and this library will follow.

from ngrx-json-api.

remmeier avatar remmeier commented on August 26, 2024 3

I make use of that already. An example looks like:

export module MetaAttribute{
    export interface Relationships extends MetaElement.Relationships{
        [key: string]: ResourceRelationship;
        type?: TypedOneResourceRelationship<MetaType>;
        oppositeAttribute?: TypedOneResourceRelationship<MetaAttribute>;
    }
    export interface Attributes extends MetaElement.Attributes{
        lazy?: boolean;
        association?: boolean;
        version?: boolean;
        derived?: boolean;
        lob?: boolean;
        nullable?: boolean;
        insertable?: boolean;
        updatable?: boolean;
        filterable?: boolean;
        sortable?: boolean;
        primaryKeyAttribute?: boolean;
    }
}
export interface MetaAttribute extends MetaElement, StoreResource{
    relationships?: MetaAttribute.Relationships;
    attributes?: MetaAttribute.Attributes;
}

the use of interfaces allows direct casting of the received json data. In my particular use case those interfaces are generated from backend declarations (java/katharsis),

from ngrx-json-api.

remmeier avatar remmeier commented on August 26, 2024 1

what do you mean with two places? you have relationships and attributes in two classes.

The big benefit of extensing StoreResource is that you also get access to state information of ngrx-json-api about a particular resource (like whether it was updated, the unchanged state of the server, etc.). That can be quite helpful.

For user, name, email it would look like:

export module User{
      export interface Attributes extends MetaElement.Attributes{
        name?: string;
        email....
    }
}
export interface User extends MetaElement, StoreResource{
    attributes?: User.Attributes;
}

The other thin I make use of are also type-safe interfaces on top of ManyQueryResult and OneQueryResult. Then I have type-safe access to the query results.

from ngrx-json-api.

blaur avatar blaur commented on August 26, 2024

Thanks a lot to both of you.

@remmeier First of all, that would still require you to maintain the attribute definitions in two places, right? But thanks a lot and it might be the way to go for me. Could you maybe expand a bit on how you would use it on my example? I am not really undersatnding how a MetaAttribute (maybe it is just the naming) should extend StoreResource which is essentially the object that is returned.

I understand that you can cast... So your result would be cast like this:
var user = response.json... Or something similar with a map function. My problem lies in how we can combine the two so that I only have the definition once.

So if I have a User with name, email and telephone how would you then apply your example above?

Sorry to be a pain in the ass ;) Looking forward to your answer.

from ngrx-json-api.

remmeier avatar remmeier commented on August 26, 2024

created a PR (#203) that fills some gaps in this area. http://www.crnk.io will be the first project that supports direct generation of ngrx-json-api/Typescript stubs from a existing backend model.

from ngrx-json-api.

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.