Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RxJS observable. How to make a re-emit once I have a reference

I have a reference to an observable, and I'm trying to trigger it to emit again after the first time it emits (or completes?). Is it possible to make this reference I've stored emit one more time?

  this._dashboardsObservable = this._http.get(PGDashService.MODEL_URL)

    .map((response: Response) => {

      this._model = this.parse(response.json());

      return this._model;

    })
    .catch((error: any) => Observable.throw(error || 'Server error'));
like image 683
BBaysinger Avatar asked Oct 17 '25 08:10

BBaysinger


1 Answers

To be specific, no, a consumer of an observable can't force the observable to re-emit. The observable is responsible for producing its own values, and the observer merely gets values pushed to it from the observable.

However, i am sure there are other ways to arrive at what you're trying to do. For example, the use of a BehaviorSubject can allow you to cache the last value emitted so the next observer to subscribe will automatically get the last value sent to it.

You'll have to be more specific about what you're actually trying to accomplish to be guided any futher.

like image 69
snorkpete Avatar answered Oct 19 '25 23:10

snorkpete



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!