Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
amollahi opened this issue May 6, 2020 · 8 comments

Comments

@amollahi
Copy link

amollahi commented May 6, 2020

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
Copy link
Member

@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
Copy link
Author

amollahi commented May 6, 2020

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
Copy link
Member

yes

@amollahi
Copy link
Author

amollahi commented May 6, 2020

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
Copy link
Member

please create stabcklitz example

@amollahi
Copy link
Author

amollahi commented May 6, 2020

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:

  • Fetch some of the Authors to AuthorState
    • if i don't have in the store the "Location"(idLocation) of an author call LocationState FechById
  • After Join Both States in a Selector to represent Author with the associated Locations

And the other way:

  • Fetch some of the Locations to LocationState
    • if i don't have in the store the "Author"(authorsIds[]) of a location call AuthorState FechById
  • After Join Both States in a Selector to represent Locations with the associated Authors

Result
So the dependencies should be like this:

  • AuthorState: should have LocationState and ApiAuthorService
  • LocationState : should have AuthorState and ApiLocationService

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

@splincode
Copy link
Member

splincode commented May 6, 2020

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
Copy link
Author

amollahi commented May 6, 2020

Ok thanks, i thought that.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants