Access to persist via thunk helpers
I'm not sure if this makes sense (perhaps there is a better way to handle this). I ran into a situation where I need to run:
store.persist.flush();
from one of the models. It's a thunk used from couple different places. It would be really nice if we could access persist:
https://github.com/ctrlplusb/easy-peasy/blob/72e60706bbf23cfab8b4ef97d6af43e96f5fad75/src/create-store.js#L155
via thunk helpers. In a similar fashion to dispatch, getActions, getStoreActions, etc.
It looks like I was able to accomplish what I needed via injections so I'm going to close this one.
@mkuklis We are running in a similar situation: Would you mind explaining how you managed to do it via injections?
@mwehnert sure. Here is our current setup:
store.js
import { createStore as createRootStore } from 'easy-peasy';
import rootModel from './models';
let store;
export const getStore = () => store;
export const createStore = () => {
store = createRootStore(rootModel, { injections: { getStore } });
return store;
};
one of the models:
const userModel = {
// ...
replace: thunk(async (actions, payload, { injections }) => {
const { getStore } = injections;
const store = getStore();
// ...
}),
// ....
}
Love it! Thanks.