Selectors are generated for a given entity when you call buildState
with a model class. The selectors may be initially destructured out of the object returned by buildState. From there, you may choose to simply export the entire selectors object, or further destructure the selectors and export only those you need to use:
It is not required to export all selectors. Through destructuring, it is recommended that you only export the selectors that you will actually use within your application. Further, we highly recommend renaming each selector to utilize the name of the model they relate to.
At BrieBug, we have moved away from naming selectors selectWhatever
in an attempt to maintain DRY principal:
Much like @ngrx/entity, when you build state for a new entity with NgRx Auto-Entity we provide a set of ready-made common selectors. These selectors allow you to retrieve the state Auto-Entity manages for you.
We have attempted to maintain compatibility with @ngrx/entity here, so we include the core standard set of selectors that are provided by that framework.
To name a few...
selectAll
selectEntities
selectIds
selectTotal
...
These selectors are returned from our buildState
utility function as a ISelectorMap<TParentState, TModel>
. See the reference documentation for the full interface definition and the complete list of selectors.