nuclear-entity-cache
Store formatted data in a centeralized cache. Inspired by the rest-api-cache
example from nuclear-js
github repo.
What?
Assume that you have structured data, mostly backend models.
// modules/api/actions.js { reactor Api }
And you would have a store to listen those dispatches, and bind handlers to it.
// modules/api/stores/api-cache-store.js { return } handlers: type: API_FETCH_SUCCESS { if !cache cache = cache return cache }
Most of the time this is well enough solution if you are dealing with only one backend,
but once you start to use different services/resources you need to create another module,
and connect the data in getter
level.
nuclear-entity-cache
tries to solve this problem by providing a very simple cache layer
module that can be used with arbitrary entity types.
Let's rewrite the example to utilize nuclear-entity-cache
// modules/api/actions.js { // get entity-cache actions by registering your reactor. let actions = Api }
That's it. One thing you have to remember is that the result you want to load has to have an id
.
Now you can use exported byId
getter to read your data.
// src/app.js let reactor = const actions = actions // in some other part of the system following getter got triggered by change handlers.getters // that's why you need an id.
install
npm install nuclear-entity-cache
licence
MIT