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

Entity Adapter #16

Closed
splincode opened this issue Nov 28, 2018 · 2 comments
Closed

Entity Adapter #16

splincode opened this issue Nov 28, 2018 · 2 comments

Comments

@splincode
Copy link
Member

A while back I prototyped something like John Papas NGRX-DATA, https://gist.github.com/amcdnl/cafd37bc9a99e2cd7653ebc023e06ffe#file-readme-md

Something we might want to think about one day.

I have created a LIB to be used as follows. I'm using it on mine.
projects:

How to use:

export class UserStateModel extends NgxsEntityStateModel<UserModel> {}

@State<UserStateModel>({
  name: 'user',
  defaults: UserStateModel.InitialState()
})
export class UserState implements NgxsOnInit {}

Methods Available:
NgxsEntityAdapter.addAll( payload, ctx );
NgxsEntityAdapter.addOne( payload, ctx );
NgxsEntityAdapter.updateOne( payload, ctx );
NgxsEntityAdapter.removeOne( payload, ctx );

NgxsEntityStateModel Class:

export class NgxsEntityStateModel<T> {
  public ids: string[];
  public entities: { [id: string]: T };
  public selected: T | null;
  public isLoading: boolean;

  static InitialState() {
    return {
      ids: [],
      entities: {},
      selected: null,
      isLoading: false
    };
  }
}

ngxs/store#541 (comment)

@splincode
Copy link
Member Author

ngxs/store#56

@JanMalch
Copy link
Collaborator

JanMalch commented Nov 29, 2018

I notice the following differences:

His proposal entity-state equivalent
Different methods for different quantities different quanitites are realized with different parameter types
selected active
error state
ids field

So I think the only relevant difference is the ids field, which is missing in the current implementation.
According to Redux Recipes it's used to indicate order.

Arrays of IDs should be used to indicate ordering. https://redux.js.org/recipes/structuringreducers/normalizingstateshape#designing-a-normalized-state

I close this issue in favor of #17

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