Own your app and do what you need, when you need
While we strive to provide as much commonly implemented functionality as we can, there can always be cases where you, the developer, must take control. Since this library is implemented much like any standard @ngrx application, it allows you to inject your own behavior whenever you need to.
If you require custom behavior for anything, you are always free to implement your own custom actions & custom effects. You are also free to hook into our library and framework by dispatching our actions from your own actions.
This could, for example, allow you to implement a custom search behavior with your own SearchEntityWhatever
action and searchEntityWhatever$
effect, and dispatch the Auto-Entity relevant success and failure actions on response, which will be handled by our meta reducer. This would integrate a custom initiating action and data from a custom service call into Auto-Entity managed state.
It is possible to integrate custom actions and effects in a variety of ways, allowing you to leverage the lower level power of NgRx when necessary, while still leveraging the ease of use offered by NgRx Auto-Entity.
Whats mine is yours, whats yours is mine!
When the need arises to create a custom action & custom effects, Auto-Entity can still help you reduce your workload. It may be that you can integrate your actions, effects and data with Auto-Entity managed state, so long as the data is compatible.
As a simple example, you may wish to create a custom action for handling type-ahead lookups that search a given entity.
You could then implement your own effect for handling this action to ensure the proper implementation and behavior:
In this case, we need switchMap
semantics...that is, we wish to cancel any previous requests that may have stale information in order to utilize the most up to date search criteria the user may have entered.
By default, Auto-Entity uses mergeMap
for all effects, which may not always be the most appropriate mapper for the use case. The default use of mergeMap
ensures that all entity actions for any entity dispatched within the store may operate concurrently, without queueing up, blocking, canceling, or dropping actions for other entities.
Take note, however, of the new actions returned by this effect:
We are returning generic actions! Since these are customers
, as long as we have built auto-entity state for the Customer
entity, you may combine custom actions you implement yourself with generic actions from the Auto-Entity library.
These actions will ultimately cause the returned customer search results to be reduced into state managed by Auto-Entity for you. You only have to create just one action. Just make sure the shape of the data returned by your custom service is compatible, or is otherwise transformed into a compatible shape.