Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
};
// using injections allows for more easily mocking of dependencies in store actions
// see https://easy-peasy.now.sh/docs/testing/testing-components.html#mocking-calls-to-services
const injections: StoreInjections = {
ipc: createIpcSender('AppModel', 'app'),
settingsService,
dockerService,
bitcoindService,
lightningFactory: new LightningFactory(),
};
const store = createReduxStore({ injections });
// export hooks directly from the store to get proper type inference
const typedHooks = createTypedHooks();
export const { useStoreActions, useStoreDispatch, useStoreState } = typedHooks;
// enable hot reload for models
if (process.env.NODE_ENV !== 'production') {
if ((module as any).hot) {
(module as any).hot.accept('./models', () => {
const models = createModel(hashHistory);
store.reconfigure(models);
});
}
}
export default store;
}
let dispatch = useStoreDispatch();
dispatch({ type: 'FOO' });
let useStoreResult = useStoreState((state: State) => state.stateNumber);
useStoreResult + 1;
let useActionResult = useStoreActions(
(actions: Actions) => actions.actionImp,
);
useActionResult(1);
let store = useStore();
store.getState().stateString + 'world';
const typedHooks = createTypedHooks();
useStoreResult = typedHooks.useStoreState(state => state.stateNumber);
useStoreResult + 1;
useActionResult = typedHooks.useStoreActions(actions => actions.actionImp);
useActionResult(1);
dispatch = typedHooks.useStoreDispatch();
dispatch({
type: 'FOO',
});
store = typedHooks.useStore();
store.getState().stateString + 'world';
let actionNoPayload = typedHooks.useStoreActions(
actions => actions.actionNoPayload,
);
actionNoPayload();
document.createElement('div'),
);
/**
* We also support typing react-redux
*/
const Counter: React.SFC<{ counter: number }> = ({ counter }) => (
<div>{counter}</div>
);
connect((state: State) => ({
counter: state.counter,
}))(Counter);
const typedHooks = createTypedHooks();
typedHooks.useAction(actions => actions.todos.addTodo)('bar');
typedHooks.useActions(actions => actions.todos.addTodo)('bar');
typedHooks.useStore(state => state.todos.items).concat(['what']);
typedHooks.useDispatch().todos.addTodo('foo');