File tree Expand file tree Collapse file tree 3 files changed +13
-14
lines changed Expand file tree Collapse file tree 3 files changed +13
-14
lines changed Original file line number Diff line number Diff line change 1
1
import { put , call } from 'redux-saga/effects'
2
2
import ExampleActions from 'App/Stores/Example/Actions'
3
- import { WeatherService } from 'App/Services/WeatherService '
3
+ import { userService } from 'App/Services/UserService '
4
4
5
5
/**
6
6
* A saga can contain multiple functions.
7
7
*
8
- * This example saga contains only one to fetch the weather temperature .
8
+ * This example saga contains only one to fetch fake user informations .
9
9
* Feel free to remove it.
10
10
*/
11
- export function * fetchTemperature ( ) {
11
+ export function * fetchUser ( ) {
12
12
// Dispatch a redux action using `put()`
13
13
// @see https://redux-saga.js.org/docs/basics/DispatchingActions.html
14
- yield put ( ExampleActions . fetchTemperatureLoading ( ) )
14
+ yield put ( ExampleActions . fetchUserLoading ( ) )
15
15
16
- // Fetch the temperature from an API
17
- const temperature = yield call ( WeatherService . fetchTemperature )
18
-
19
- if ( temperature ) {
20
- yield put ( ExampleActions . fetchTemperatureSuccess ( temperature ) )
16
+ // Fetch user informations from an API
17
+ const user = yield call ( userService . fetchUser )
18
+ if ( user ) {
19
+ yield put ( ExampleActions . fetchUserSuccess ( user ) )
21
20
} else {
22
21
yield put (
23
- ExampleActions . fetchTemperatureFailure ( 'There was an error while fetching the temperature .' )
22
+ ExampleActions . fetchUserFailure ( 'There was an error while fetching user informations .' )
24
23
)
25
24
}
26
25
}
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ import NavigationService from 'App/Services/NavigationService'
8
8
export function * startup ( ) {
9
9
// Dispatch a redux action using `put()`
10
10
// @see https://redux-saga.js.org/docs/basics/DispatchingActions.html
11
- yield put ( ExampleActions . fetchTemperature ( ) )
11
+ yield put ( ExampleActions . fetchUser ( ) )
12
12
13
13
// Add more operations you need to do at startup here
14
14
// ...
Original file line number Diff line number Diff line change 1
1
import { takeLatest } from 'redux-saga/effects'
2
2
import { ExampleTypes } from 'App/Stores/Example/Actions'
3
3
import { StartupTypes } from 'App/Stores/Startup/Actions'
4
- import { fetchTemperature } from './ExampleSaga'
4
+ import { fetchUser } from './ExampleSaga'
5
5
import { startup } from './StartupSaga'
6
6
7
7
export default function * root ( ) {
@@ -11,7 +11,7 @@ export default function* root() {
11
11
*/
12
12
// Run the startup saga when the application starts
13
13
takeLatest ( StartupTypes . STARTUP , startup ) ,
14
- // Call `fetchTemperature ()` when a `FETCH_TEMPERATURE ` action is triggered
15
- takeLatest ( ExampleTypes . FETCH_TEMPERATURE , fetchTemperature ) ,
14
+ // Call `fetchUser ()` when a `FETCH_USER ` action is triggered
15
+ takeLatest ( ExampleTypes . FETCH_USER , fetchUser ) ,
16
16
]
17
17
}
You can’t perform that action at this time.
0 commit comments