Created
July 30, 2018 10:32
-
-
Save axelnormand/428a0494afd030d6fd5d0acb7338b5db to your computer and use it in GitHub Desktop.
React Native Storybook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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