store.ts 892 B

1234567891011121314151617181920212223242526272829303132333435
  1. import { Action, createStore, createTypedHooks, action } from "easy-peasy";
  2. import { settings, Settings } from "./settings";
  3. import { loading, Loading } from "./loading";
  4. import { links, Links } from "./links";
  5. import { auth, Auth } from "./auth";
  6. export interface StoreModel {
  7. auth: Auth;
  8. links: Links;
  9. loading: Loading;
  10. settings: Settings;
  11. reset: Action<StoreModel>;
  12. }
  13. let initState: any = {};
  14. export const store: StoreModel = {
  15. auth,
  16. links,
  17. loading,
  18. settings,
  19. reset: action(() => initState)
  20. };
  21. const typedHooks = createTypedHooks<StoreModel>();
  22. export const useStoreActions = typedHooks.useStoreActions;
  23. export const useStoreDispatch = typedHooks.useStoreDispatch;
  24. export const useStoreState = typedHooks.useStoreState;
  25. export const initializeStore = (initialState?: StoreModel) => {
  26. initState = initialState;
  27. return createStore(store, { initialState });
  28. };