Created
January 14, 2019 09:20
-
-
Save Calvin-Huang/f36e36df4f749b8cd088bb56278e5f2c 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 }) => ( | |
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