Skip to content

Instantly share code, notes, and snippets.

@axelnormand
Created July 30, 2018 10:32
Show Gist options
  • Save axelnormand/428a0494afd030d6fd5d0acb7338b5db to your computer and use it in GitHub Desktop.
Save axelnormand/428a0494afd030d6fd5d0acb7338b5db to your computer and use it in GitHub Desktop.
React Native Storybook
import { action } from '@storybook/addon-actions';
import { Store } from 'redux';
import { getInitialState } from '../state';
/**
* Ready only mock store with addon actions upon dispatch
*
* Defaults to having a valid App initial state as imported via state.ts
*/
export const getStorybookStore = (): Store<any> => {
const state = getInitialState();
return {
getState: () => state,
dispatch: (dispatchedAction: any) => {
const msg = `Redux dispatch: ${JSON.stringify(dispatchedAction)}`;
action('dispatch')(msg);
return dispatchedAction;
},
subscribe: (_: () => void) => {
action('subscribe')('Redux subscribe called');
const noop = () => null;
return noop;
},
replaceReducer: () =>
action('replaceReducers')('Redux replaceReducers called'),
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment