11
如何在創建Observable後添加元素時如何實現場景,完全可以實現?在觀察者模式中,我只會觸發事件。你有什麼想法嗎?創建rx後添加元素Observable
import rx.lang.scala._
val target = Observable(1,2,3,4)
val subscription1 = target subscribe(println(_))
val subscription2 = target subscribe(println(_))
def addToObservable(toAdd: Int, target: Observable[Int]): Observable[Int] = {
target/*.addElementAndNotifyObservers(toAdd)*/
}
addToObservable(4, target) //should print 4 on all subscriptions
addToObservable(6, target) //should print 6 on all subscriptions