Skip to content

Instantly share code, notes, and snippets.

@Calvin-Huang
Last active January 14, 2019 09:19
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Calvin-Huang/26760666248a5c2b3947db80ef8a1c4c to your computer and use it in GitHub Desktop.
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