如何使用rxjs观察对象更改5 [英] How to watch object changes with rxjs 5

查看:92
本文介绍了如何使用rxjs观察对象更改5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想查看一个对象,因此所有订阅者都会收到任何更改通知。

I would like to watch over an object, so all the subscribers will be informed for any changes of it.

我看到它已经之前
然而答案是无关紧要的,因为RXjs verion 5不包括<在它的API中强> ofObjectChanges 。

我看过一些hacks,比如创建一个返回函数的观察者:

I've looked at some "hacks" like creating an observer which return a function:

let myObservable =  new Observable((observer) => {
  return (data) => {
    observer.next(data)
  }
}) 
//...
myObservable.subscribe()('someData')

但是,我确信有更优雅的方式。
任何想法?

However, I'm sure there is more elegant way of doing it. Any Ideas?

推荐答案

您需要使用行为主题。 https://github.com/Reactive-扩展/ RxJS / blob / master / doc / api / subject / behaviorsubject.md

You need to use Behavior Subject . https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/subjects/behaviorsubject.md

这篇关于如何使用rxjs观察对象更改5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆