我在 RxSwift 中有这个:
func foo() -> Observable<Int> {
let subject = RxSwift.ReplaySubject<Int>.create(bufferSize: 1)
return subject.asObservable()
}
如何在 ReactiveKit 中实现相同的概念?
我在 RxSwift 中有这个:
func foo() -> Observable<Int> {
let subject = RxSwift.ReplaySubject<Int>.create(bufferSize: 1)
return subject.asObservable()
}
如何在 ReactiveKit 中实现相同的概念?
使用当前处于测试阶段(rk3 分支)的 ReactiveKit 3,您可以执行以下操作:
func foo() -> Signal<Int, NoError> {
let subject = ReplaySubject<Int, NoError>(bufferSize: 1)
return subject.toSignal()
}
在 ReactiveKit 2 中,ReplaySubject 被泛化为事件:
func foo() -> Stream<Int> {
let subject = ReplaySubject<StreamEvent<Int>>(bufferSize: 1)
return Stream(rawStream: subject.toRawStream())
}
或者
func foo() -> Operation<Int, Error> {
let subject = ReplaySubject<OperationEvent<Int>>(bufferSize: 1)
return Operation(rawStream: subject.toRawStream())
}