ngxs-labs / entity-state

⏱ WIP: Entity adapter
48 stars 12 forks source link

Expose internal.ts to public to easily extend EntityState using same logic #212

Open amollahi opened 4 years ago

amollahi commented 4 years ago

I generalize some CRUD operations extending the ngxs-labs/entity-state plugin.

It's easy to extend this library, but i would like to use internal.ts methods so i don't need to copy them in my application.

Also i hope to get a Stable release soon available on NPM. 😉

splincode commented 4 years ago

@am4apps Today, full attention is paid to the new project and plugin: https://github.com/ngxs-labs/data/blob/master/docs/pages/entity.md

I'm not sure when work on the @ngxs-labs/entity-state plugin will continue

amollahi commented 4 years ago

I check the data plugin.

I guess it works like a data-service, so you need to subscribe yourself if you want to perform the "Action"(method call). ¿Right?

How it will look a FechAll method in the state like this:

public fetchAll(): Observable<any> {
    return this.apiService.fetchAll()
        .pipe(
            tap((array) => this.setEntitiesAll(array))
        );
}

And after you will need to subscribe in the component, ¿Right?

splincode commented 4 years ago

yes

amollahi commented 4 years ago

There's one more thing, ¿how you deal in the ngxs-labs/data plugin with circular dependencies?

If i am not mistaken you should inject other states to call their methods or to join data from multiple states.

State A => Call State B method(Action) State B => Call State A method(Action)

or

State A selector get data from State B State B selector get data from State A

splincode commented 4 years ago

please create stabcklitz example

amollahi commented 4 years ago

Whould be easier with a more specific model:

export interface IAuthorDTO {
    avatar?: string;
    bornDate?: Date;
    idLocation?: number;
    id?: number;
    name?: string;
}

export interface ILocationDTO {
    authorsIds?: number[];
    city?: string;
    country?: string;
    id?: number;
}

What i am trying is:

And the other way:

Result So the dependencies should be like this:


With the action aproach this is not a problem because you will dispatch actions, and you will not have the state as depency.

splincode commented 4 years ago
With the action aproach this is not a problem because you will dispatch actions, and you will not have the state as depency.

here I will not help you with anything, use native NGXS

But in general, if you were to use even regular services (rxjs statefull) instead of NGXS, this is a bad approach to have circular dependencies

amollahi commented 4 years ago

Ok thanks, i thought that.

I was checking to work with normalized data with NGXS similar to this Akita Normalized Data