Git Product home page Git Product logo

Comments (6)

splincode avatar splincode commented on September 14, 2024

Give examples of expected behavior so that I can implement this

from data.

 avatar commented on September 14, 2024

I will put together a minimal example of what we're trying to achieve later today.

from data.

 avatar commented on September 14, 2024

Let's say we wanted additional properties in our EntityCollectionsReducer like loading and loaded:

export class MyCollectionRepository<V, K extends EntityIdType = EntityIdType>
    extends NgxsDataEntityCollectionsRepository<V, K> {

    @Computed()
    public get loading(): boolean {
        return this.snapshot.loading;
    }

    @Computed()
    public get loaded(): boolean {
        return this.snapshot.loaded;
    }

    @DataAction()
    public setLoading(@Payload('loading') loading: boolean): void {
        const state = this.getState();
        this.setEntitiesState({
            ...state,
            loading,
        });
    }

    @DataAction()
    public setLoaded(@Payload('loaded') loaded: boolean): void {
        const state = this.getState();
        this.setEntitiesState({
            ...state,
            loaded,
        });
    }
}

In order to get this working, there would be a few things we need to adjust. The most important is a new class type generic:

export class NgxsDataEntityCollectionsRepository<
    V,
    K extends number | string = EntityIdType,
    C extends NgxsEntityCollections<V, K> = NgxsEntityCollections<V, K>
>

Then we could simply use this in our Collection:

export class MyCollectionRepository<V, K extends EntityIdType = EntityIdType>
    extends NgxsDataEntityCollectionsRepository<V, K, MyCollection<V, K>>

There might be another caveat... for all the operations used in NgxsDataEntityCollectionsRepository, the rest of the state would need to be persisted. So addEntityOne would use this call to setEntitiesState:

        this.setEntitiesState({
            ...state,
            ids: [...state.ids, id],
            entities: { ...state.entities, [id]: entity },
        });

If this is hard to follow along, I can make an example repository with the overrides in place.

Edit:
Or would you rather suggest we implement something from scratch for this? Possibly NgxsDataEntityCollectionsRepository just wasn't supposed to support this case.

from data.

splincode avatar splincode commented on September 14, 2024

I understand you, yes, I think no problem will add this soon

from data.

splincode avatar splincode commented on September 14, 2024
### Extending NgxsDataEntityCollectionsRepository

move to Entity.md

from data.

splincode avatar splincode commented on September 14, 2024

released in v3.0.0-rc.14

from data.

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.