|
|
@ -1,6 +1,6 @@ |
|
|
|
import { call, put, takeEvery, takeLatest } from 'redux-saga/effects'; |
|
|
|
import { fetchBikes as fetchBikesAction, setBikes, setBikesIsFetching, setBikesFetched, |
|
|
|
setBikesFetchFailed, setBikeSaved, setBikeSaveFailed, setBikeIsSaving, saveBike as saveBikeAction } from './actions'; |
|
|
|
setBikesFetchFailed, setBikeSaved, setBikeSaveFailed, setBikeIsSaving, saveBike as saveBikeAction, mergeBike } from './actions'; |
|
|
|
import { normalize, denormalize } from 'normalizr'; |
|
|
|
import * as schema from './schema'; |
|
|
|
import Api from './services'; |
|
|
@ -28,14 +28,14 @@ function* watchFetchBikes() { |
|
|
|
function* saveBike(action) { |
|
|
|
try { |
|
|
|
yield put({ type: setBikeIsSaving.toString(), payload: true }); |
|
|
|
const bike = yield call(Api.saveBike(action.payload)); |
|
|
|
yield put({ type: setBikes.toString(), payload: normalize([state])}) |
|
|
|
yield put({ type: setBikeSaved, payload: true}) |
|
|
|
const bike = yield call(Api.saveBike, action.payload); |
|
|
|
yield put({ type: mergeBike.toString(), payload: normalize([bike], schema.bikes)}) |
|
|
|
yield put({ type: setBikeSaved.toString(), payload: true}) |
|
|
|
} catch (e) { |
|
|
|
yield put({ type: setBikeSaveFailed, payload: false }); |
|
|
|
throw(e); |
|
|
|
} finally { |
|
|
|
yield put({ type: setBikeIsSaving.toSource(), payload: false }); |
|
|
|
yield put({ type: setBikeIsSaving.toString(), payload: false }); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|