ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## `refCount`相关问题 定义: > `refCount` makes the multicasted Observable automatically start executing when the first subscriber arrives, and stop executing when the last subscriber leaves. - 方法`publish()`和`share()`的区别: > share() == publish().refCount() == multiCast(new Rx.Subject()).refCount() ``` const x = Rx.Observable.of(1) .do(x => console.log('side effect')) // publish = multicast(new Rx.Subject()).refCount() const y = x.multicast(new Rx.Subject()).refCount(); y.subscribe(console.log); y.subscribe(console.log); console.log('-------------------------'); // share = multicast(() => new Rx.Subject()).refCount() const z = x.multicast(() => new Rx.Subject()).refCount(); z.subscribe(console.log); z.subscribe(console.log); ``` 结果: ``` side effect 1 ------------------------- side effect 1 side effect 1 ``` - `publish()` 相关alias ``` publish = multicast + Subject publishReplay = multicast + ReplaySubject publishBehavior = multicast + BehaviorSubject publishLast = multicast + AsyncSubject ```