store.ts 634 B

1234567891011121314151617181920212223242526
  1. import { Store } from 'redux';
  2. import { initialKeyedVariablesState } from 'app/features/variables/state/keyedVariablesReducer';
  3. import { StoreState } from 'app/types';
  4. export let store: Store<StoreState>;
  5. export function setStore(newStore: Store<StoreState>) {
  6. store = newStore;
  7. }
  8. export function getState(): StoreState {
  9. if (!store || !store.getState) {
  10. return { templating: { ...initialKeyedVariablesState, lastKey: 'key' } } as StoreState; // used by tests
  11. }
  12. return store.getState();
  13. }
  14. export function dispatch(action: any) {
  15. if (!store || !store.getState) {
  16. return;
  17. }
  18. return store.dispatch(action);
  19. }