走进rxjs的世界 - 万物皆流 - Everything is a stream
一些使用案例
the pollTasks() method emits a call every 10 seconds, which triggers the call inside of flatMapLatest – we’re basically ignoring the result of that event, and using it to trigger the http.get method to fetch our data. We’ll map it into JSON each time.
pollTasks方法返回一個Observable對象,封裝了一個10秒間隔的周期性調用,調用內部會執行http操作讀取tasks.json文件,將結果以json格式返回。
The caller of our pollTasks() method just gets an observable, which is emitting content every 10 seconds.
調用pollTasks方法,只會返回一個Observable對象,這個Observable對象subscribe之后,會每隔10秒產生內容。調用unsubscribe關閉。
Also the flatMapLatest call is really interesting – any calls generated by previous events are canceled, including their in-flight HTTP method calls. Try doing that with a promise!
flagMapLatest是一個強力方法,這里將其當作一種engine使用:所有基于之前發生的事件觸發的調用都會自動被cancel,包括正在進行中的in-flight HTTP調用。很難想象使用promise實現類似的方法,會花費多大的工作量。
參考文獻
總結
以上是生活随笔為你收集整理的走进rxjs的世界 - 万物皆流 - Everything is a stream的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SAP gateway 后台系统的 OD
- 下一篇: 商汤发布“商量SenseChat”语言大