Last active
January 14, 2019 09:19
-
-
Save Calvin-Huang/26760666248a5c2b3947db80ef8a1c4c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
export const scheduleEpic = action$ => action$.pipe( | |
ofType(FETCH_SCHEDULE_REQUEST), | |
debounceTime(300), | |
switchMap(({ payload }) => { | |
return ajax | |
.getJSON(`${API_URL}/AvailableSeatStatusList/${payload.OriginStationID}`) | |
.pipe( | |
map(response => ({ | |
...payload, | |
availableSeatTable: availableFormater(response[0], payload.DestinationStationID), | |
})), | |
catchError(error => of({ type: FETCH_SCHEDULE_FAILURE, error: error.xhr.response })), | |
) | |
}), | |
switchMap(({ | |
availableSeatTable, | |
OriginStationID, | |
DestinationStationID, | |
TrainDate, | |
}) => { | |
if (!availableSeatTable.length) { | |
return [fetchSuccess(availableSeatTable)] | |
}; | |
return ajax | |
.getJSON(`${API_URL}/DailyTimetable/OD/${OriginStationID}/to/${DestinationStationID}/${TrainDate}`) | |
.pipe( | |
map((response) => { | |
const timeTable = timeTableFormater(response); | |
return fetchSuccess(leftJoin(availableSeatTable, timeTable)); | |
}), | |
catchError(error => of({ | |
type: FETCH_SCHEDULE_FAILURE, | |
error: error.xhr.response, | |
}) | |
), | |
); | |
}), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment