michaelkrone / ngrx-normalizr

Managing normalized state in ngrx applications - transparently
https://michaelkrone.github.io/ngrx-normalizr/
MIT License
50 stars 17 forks source link

Remove all action #28

Closed mecsco closed 6 years ago

mecsco commented 6 years ago

Following on from #26 which mentions @ngrx/entity (https://github.com/ngrx/platform/blob/master/docs/entity/adapter.md) and its support for updating partial data, it may also be useful to have the equivalent of its 'removeAll' action so that all the normalized entities can be cleared out without needing to call RemoveData multiple times with all the individual IDs

I suppose different users might have different requirements - for some it could be to empty everything, for others it could be to specify a certain key and only empty that and all its children (although in that case I guess it could get a bit messy if the children were shared with other parent entities that had a different key that weren't being cleared).

michaelkrone commented 6 years ago

For removing child entities, the RemoveData action can take a map of schema keys mapped to property names for entities which should be removed along with the 'parent' entity. Of course this should only be used for 1:1 relations. To remove an entity completely, you might dispatch a SetData action with an empty Array.

mecsco commented 6 years ago

Ah understood - I think SetData should cover my scenario, I'll close this ticket