infodev
infodev

Reputation: 5245

can't pipe on observable not working using ngrx

I get data from ngrx using a selector

  schedules$ = this.store.pipe(select(selectSchedulingsTimes));

Then in Oninit I pipe on the observable

ngOnInit() {
  this.store.dispatch(new GetSelectedItem());
  this.store.dispatch(new GetSchedules());
  let data = this.schedules$.pipe(
    map((elm: ISchedule[]) => {
      return elm.map((elm: ISchedule) => {
        return { tp_org_r: elm.tp_org_r, tp_des_r: elm.tp_des_r };
      });
    })
  );

}

I get never enter inside the map I don't know why ?

Upvotes: 0

Views: 468

Answers (1)

Dams
Dams

Reputation: 61

Because let data is a cold observable and won't trigger until you call the method subscribe. check more on Hot vs Cold Observables

data.subscribe(console.log)

When does an Observable begin emitting its sequence of items? It depends on the Observable. A “hot” Observable may begin emitting items as soon as it is created, and so any observer who later subscribes to that Observable may start observing the sequence somewhere in the middle. A “cold” Observable, on the other hand, waits until an observer subscribes to it before it begins to emit items, and so such an observer is guaranteed to see the whole sequence from the beginning.

In some implementations of ReactiveX, there is also something called a “Connectable” Observable. Such an Observable does not begin emitting items until its Connect method is called, whether or not any observers have subscribed to it.

Upvotes: 1

Related Questions