Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
/**
Eventモデル
- requestState: API通信の状態を扱う
- disposeBag: RxSwiftで不要なstreamを削除するためのクラス
*/
struct EventsModel {
internal let requestState = Variable(RequestState.Stopped)
private let disposeBag = DisposeBag()
}
extension EventsModel {
/**
- Eventの一覧を取得する
- APIレスポンスは、self.requestStateに格納
*/
func fetchEventList(count: Int) {
requestState.value = .Requesting
EventsRequest
.GetEvents(count)
.request()
.map{ try! decodeValue($0) as EventListResponse }
.subscribe(
onNext: {
self.requestState.value = .Response($0)
}, onError: {
self.requestState.value = .Error($0)
}
)
.addDisposableTo(disposeBag)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment