Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to change the id in ngrx/entities?

Is it necessary to have ids in ngrx/entities that will not be changed? I want to use string property path as id. It is uniq. But it can be changed. Should I use uuid as ids in this case?

like image 851
mr__brainwash Avatar asked May 30 '18 17:05

mr__brainwash


Video Answer


2 Answers

You can pass in a function to override the default id selection when creating your adapter:

export const adapter: EntityAdapter<Model> = createEntityAdapter({
  selectId: (model: Model) => model.modelId,
});
like image 74
bc1105 Avatar answered Oct 22 '22 12:10

bc1105


We needed to update the Ids in the EntityAdapter because the API returns the unique ID, for future references, which is not available when first adding it to the store. So you could change it yourself if you want to.

const updateSelectedRooms = new selectedRoomsActions.UpdateSelectedRooms(
            {
                entities: [
                    {
                        changes: {
                            id: mockResponse.data.rooms[0].roomId,
                            pricing: mockResponse.data.rooms[0].pricing,
                        },
                        id: '1234-5678',
                    },
                ],
            },
        );
like image 4
rvdm Avatar answered Oct 22 '22 11:10

rvdm