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