-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cache(), share(), publish().refCount() and publishReplay().refCount() do not work as told #1405
Comments
I'm still new to typescript, but I have a feeling that it's because every time you call the getter, it creates a new observable. Try something like this? export class Service {
private _restStream: Observable<RestModel>;
public get RestStream(): Observable<RestModel> {
return this._restStream;
}
constructor() {
this._restStream = this.getStuff().publishReplay().refCount();
}
} |
@SuperManitu I have to say that @tbugrara is right on. Think of an Observable like a function. In this case, it's a function that starts a request the first time it's called (subscribed to) and shares that request (or it's result) with everyone else that calls it (subscribes to it). @tbugrara's example is exactly right. Also in |
Closing this for now, as it's been answered, feel free to reopen if you think there is an actual bug or issue with the library to be addressed. |
I have to reopen, because that was what I tried in the first place, saving |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hi,
I'm fairly new to RxJS, so this could be a misunderstanding, but for the following situation:
I have a Service singleton that queries a REST API, like this:
"this.getStuff()" queries the API and returns an Observable
In my understanding, every further transformation of the RestStream in other classes shouldnt requery the API, because I cached it (Say for example I want a part of the RestModel and add a function somewhere that returns
service.RestStream.map(<something>)
). So any subscribtion to the service or depenent services that further transform the Observable should not requery to API.I guess this is wrong, because I get plenty of requests in chrome to an url that is only requested in that getStuff() method.
What is the correct way to implement the behavior that I want? (I already tried the operators in the heading)
The text was updated successfully, but these errors were encountered: