angular-architects / ngrx-toolkit

Various Extensions for the NgRx Signal Store
MIT License
177 stars 23 forks source link

WithDevTools code repetition when used with withRedux #80

Open marcindz88 opened 3 months ago

marcindz88 commented 3 months ago

Hi I would love to see a feature where we can define updateState with redux on functions more easily without repeating action name twice. Current code to include action name in redux dev tools looks like this:

on(actions.updateSomeEntity, (state, { entity }) =>
  updateState(
    state,
    actions.updateSomeEntity.type,
    updateEntity({ id: entity.id, changes: entity }, { collection: 'entity' })
    )
);

I tried to create a wrapper that will accept on with some configuration, but failed because some internal types are not exported.

Also I have not seen anything the docs about updateState so it's worth including I think, as I found it by accident.

marcindz88 commented 3 months ago

The solution could include moving the updateState logic into the on function, resulting in code:

on(actions. updateSomeEntity, ({ entity }) => addEntity(entity, ENTITY_COLLECTION));
rainerhahnekamp commented 3 months ago

@marcindz88, I've updated the docs and added updateState. I agree that your version of the on function is something we should add but I think, it will be available in the new version of the redux where we decouple actions from the store.