Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Updated readme
  • Loading branch information
piotrwitek committed Feb 12, 2019
commit 12bcb3bc2dd1bac5ee87fada8b5cfed0af647a3e
52 changes: 28 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ const mapDispatchToProps = (dispatch: Dispatch<ActionType>) => ({
#### - redux connected counter

```tsx
import Types from 'Types';
import Types from 'MyTypes';
import { connect } from 'react-redux';

import { countersActions, countersSelectors } from '../features/counters';
Expand Down Expand Up @@ -670,7 +670,7 @@ export default () => <FCCounterConnected label={'FCCounterConnected'} />;
#### - redux connected counter (verbose)

```tsx
import Types from 'Types';
import Types from 'MyTypes';
import { bindActionCreators, Dispatch } from 'redux';
import { connect } from 'react-redux';

Expand Down Expand Up @@ -714,7 +714,7 @@ export default () => (
#### - with own props

```tsx
import Types from 'Types';
import Types from 'MyTypes';
import { connect } from 'react-redux';

import { countersActions, countersSelectors } from '../features/counters';
Expand Down Expand Up @@ -1100,11 +1100,10 @@ export default combineReducers<TodosState, TodosAction>({
return [...state, action.payload];

case TOGGLE:
return state.map(
item =>
item.id === action.payload
? { ...item, completed: !item.completed }
: item
return state.map(item =>
item.id === action.payload
? { ...item, completed: !item.completed }
: item
);

default:
Expand Down Expand Up @@ -1207,6 +1206,7 @@ When creating a store instance we don't need to provide any additional types. It
> The resulting store instance methods like `getState` or `dispatch` will be type checked and will expose all type errors

```tsx
import { RootAction, RootState, Services } from 'MyTypes';
import { createStore, applyMiddleware } from 'redux';
import { createEpicMiddleware } from 'redux-observable';

Expand All @@ -1215,21 +1215,27 @@ import rootReducer from './root-reducer';
import rootEpic from './root-epic';
import services from '../services';

export const epicMiddleware = createEpicMiddleware(rootEpic, {
export const epicMiddleware = createEpicMiddleware<
RootAction,
RootAction,
RootState,
Services
>({
dependencies: services,
});

function configureStore(initialState?: object) {
// configure middlewares
const middlewares = [epicMiddleware];
// compose enhancers
const enhancer = composeEnhancers(applyMiddleware(...middlewares));
// create store
return createStore(rootReducer, initialState!, enhancer);
}
// configure middlewares
const middlewares = [epicMiddleware];
// compose enhancers
const enhancer = composeEnhancers(applyMiddleware(...middlewares));

// rehydrate state on app start
const initialState = {};

// pass an optional param to rehydrate state on app start
const store = configureStore();
// create store
const store = createStore(rootReducer, initialState, enhancer);

epicMiddleware.run(rootEpic);

// export store singleton instance
export default store;
Expand All @@ -1246,16 +1252,16 @@ export default store;

```tsx
import { RootAction, RootState, Services } from 'MyTypes';
import { combineEpics, Epic } from 'redux-observable';
import { Epic } from 'redux-observable';
import { tap, ignoreElements, filter } from 'rxjs/operators';
import { isOfType } from 'typesafe-actions';

import { todosConstants } from '../todos';

// contrived example!!!
const logAddAction: Epic<RootAction, RootAction, RootState, Services> = (
export const logAddAction: Epic<RootAction, RootAction, RootState, Services> = (
action$,
store,
state$,
{ logger }
) =>
action$.pipe(
Expand All @@ -1268,8 +1274,6 @@ const logAddAction: Epic<RootAction, RootAction, RootState, Services> = (
ignoreElements()
);

export default combineEpics(logAddAction);

```

[⇧ back to top](#table-of-contents)
Expand Down
2 changes: 1 addition & 1 deletion README_SOURCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ Can be imported in various layers receiving or sending redux actions like: reduc
When creating a store instance we don't need to provide any additional types. It will set-up a **type-safe Store instance** using type inference.
> The resulting store instance methods like `getState` or `dispatch` will be type checked and will expose all type errors

::codeblock='playground/src/store/store.ts'::
::codeblock='playground/src/store/index.ts'::

---

Expand Down