It’s possible to define middleware functions both for a
EntityStore. For example, in
EntityStore we can add the following methods:
preAddEntity() middleware is called when we invoke the
EntityStore.add() methods with the newly added entity, and gives you the possibility to modify it before inserting it into the store.
preUpdateEntity() middleware is called with the previous entity’s data, as well as the updated version of it, whenever we call any
EntityStore method that updates an entity, for instance,
In addition to that, we’ve added the
preUpdate() middleware that’s supported in both stores, and is called with the previous and the current state.
This middleware is called whenever we call
Store.update(). For example:
These can also be useful for debugging purposes. For example, logging who's updating the store.
In case you want to use the this context inside the hook, you need to use the