Skip to content

Instantly share code, notes, and snippets.

@Calvin-Huang
Created January 14, 2019 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Calvin-Huang/f36e36df4f749b8cd088bb56278e5f2c to your computer and use it in GitHub Desktop.
Save Calvin-Huang/f36e36df4f749b8cd088bb56278e5f2c to your computer and use it in GitHub Desktop.
export const scheduleEpic = action$ => action$.pipe(
ofType(FETCH_SCHEDULE_REQUEST),
debounceTime(300),
switchMap(({ payload }) => (
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