-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add redux-actions. Upgrade dependencies
- Loading branch information
vinogradov
committed
Aug 2, 2017
1 parent
96e8efe
commit 21af568
Showing
9 changed files
with
204 additions
and
20 deletions.
There are no files selected for viewing
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
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
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
11 changes: 11 additions & 0 deletions
11
src/examples/redux/separate-files-redux-actions/actions.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {createActions} from 'redux-actions'; | ||
|
||
export const { | ||
action1, | ||
action2, | ||
action3 | ||
} = createActions( | ||
'ACTION1', | ||
'ACTION2', | ||
'ACTION3' | ||
); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {createStore, applyMiddleware, combineReducers} from 'redux'; | ||
import createSagaMiddleware from 'redux-saga'; | ||
import 'regenerator-runtime/runtime'; // eslint-disable-line import/no-extraneous-dependencies | ||
import logger from 'redux-logger'; | ||
import reducer from './reducers'; | ||
import sagas from './sagas'; | ||
import {action1} from './actions'; | ||
|
||
const sagaMiddleware = createSagaMiddleware(); | ||
|
||
const store = createStore( | ||
combineReducers({reducer}), | ||
applyMiddleware(sagaMiddleware, logger)); | ||
|
||
sagaMiddleware.run(sagas); | ||
|
||
store.dispatch(action1({value1: 1})); |
25 changes: 25 additions & 0 deletions
25
src/examples/redux/separate-files-redux-actions/reducers.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {handleActions} from 'redux-actions'; | ||
import { | ||
action1, | ||
action2, | ||
action3} from './actions'; | ||
|
||
const INITIAL_STATE = {}; | ||
|
||
export default handleActions({ | ||
[action1](state, {payload: {value1}}) { | ||
return { | ||
...state, | ||
value1 | ||
}; | ||
}, | ||
[action2](state, {payload: {value2}}) { | ||
return { | ||
...state, | ||
value2 | ||
}; | ||
}, | ||
[action3]() { | ||
return INITIAL_STATE; | ||
} | ||
}, INITIAL_STATE); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {take} from 'redux-saga/effects'; | ||
import {action1} from './actions'; | ||
|
||
export default function* watchAction1() { | ||
while (true) { // eslint-disable-line no-constant-condition | ||
yield take(action1); | ||
console.log('watchAction1 saga!'); // eslint-disable-line no-console | ||
} | ||
} |
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
Oops, something went wrong.