获得以前的可观察结果,以加入管道RXJS

发布于 2025-01-23 00:43:21 字数 1747 浏览 2 评论 0原文

第一个HTTP调用以获取发货数据 如果发货数据不可用 将停止显示错误

如果发货数据可用我需要致电第二和第三个呼叫paralalley

我使用叉子加入来调用paralell请求,并在获取叉子加入数据之后如何在叉子上加入地图方法中使用装运数据。

   from(getShipment(this.data.CardId))
              .pipe(
                filter(shipmentData => shipmentData != undefined),
                tap(shipmentData => {
                  if (shipmentData.ShipmentId === null || shipmentData.ShipmentId === "") {
                    throw "Shipment needs to be connected"
                  }
                }),
                //I NEED TO PASS THIS SHIPMENT DATA TO FORK JOIN PIPE METHOD
                map(shipmentData => shipmentData),                
                concatMap(shipmentData =>
                  forkJoin([
                    getOrderLineAllocationByCardIdObservable(this.data.CardId),
                    getLotsByCardIdObservable(this.data.CardId)
                  ])
                    .pipe(
                      filter(response => response != undefined),
                      map(([inventoryData, lotsData],shipmentData) => {
                                               
                       //I NEED TO ACCESS SHIPMENT DATA IN HERE
                       //SHIPMENT DATA NOT AVAILABLE IN HERE
        
                      })
                    )
                ),
                // Catch errors thrown above
                catchError(error => {                      
                  return EMPTY;
                }),
                // Always finish by Hiding Loading indicator
                finalize(() => this.store.dispatch(setLoadingSpinner({showLoading: false})))
              )
              .subscribe();

First Http call to fetch Shipment Data
IF shipment data is NOT AVAILABLE exceution will be stop with showing error

IF shipment data is AVAILABLE i need to call second and third calls paralalley

I used fork join to call paralell request and after fetching fork join data how to use shipment data inside in the fork join map method.

   from(getShipment(this.data.CardId))
              .pipe(
                filter(shipmentData => shipmentData != undefined),
                tap(shipmentData => {
                  if (shipmentData.ShipmentId === null || shipmentData.ShipmentId === "") {
                    throw "Shipment needs to be connected"
                  }
                }),
                //I NEED TO PASS THIS SHIPMENT DATA TO FORK JOIN PIPE METHOD
                map(shipmentData => shipmentData),                
                concatMap(shipmentData =>
                  forkJoin([
                    getOrderLineAllocationByCardIdObservable(this.data.CardId),
                    getLotsByCardIdObservable(this.data.CardId)
                  ])
                    .pipe(
                      filter(response => response != undefined),
                      map(([inventoryData, lotsData],shipmentData) => {
                                               
                       //I NEED TO ACCESS SHIPMENT DATA IN HERE
                       //SHIPMENT DATA NOT AVAILABLE IN HERE
        
                      })
                    )
                ),
                // Catch errors thrown above
                catchError(error => {                      
                  return EMPTY;
                }),
                // Always finish by Hiding Loading indicator
                finalize(() => this.store.dispatch(setLoadingSpinner({showLoading: false})))
              )
              .subscribe();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寒冷纷飞旳雪 2025-01-30 00:43:21

只需删除shipmentData作为您的地图功能的参数,它已经在那里:

import {
  of,
  map,
  Observable,
  from,
  filter,
  tap,
  concatMap,
  forkJoin,
  catchError,
  finalize,
} from 'rxjs';

// Open the console in the bottom right to see results.
function getShipment(x) {
  return new Promise(function (res, rej) {
    res({ key: 'hi, im shipmentData', ShipmentId: 989 });
  });
}

function getOrderLineAllocationByCardIdObservable(x) {
  return of(1);
}

function getLotsByCardIdObservable(x) {
  return of(2);
}

from(getShipment(1))
  .pipe(
    filter((shipmentData) => shipmentData != undefined),
    tap((shipmentData: any) => {
      if (shipmentData.ShipmentId === null || shipmentData.ShipmentId === '') {
        throw 'Shipment needs to be connected';
      }
    }),
    concatMap((shipmentData) =>
      forkJoin(
        getOrderLineAllocationByCardIdObservable(666),
        getLotsByCardIdObservable(666)
      ).pipe(
        filter((response) => response != undefined),
        map(([inventoryData, lotsData]) => {
          console.log(shipmentData);
        })
      )
    ),
    // Catch errors thrown above
    catchError((error) => {
      return of();
    }),
    // Always finish by Hiding Loading indicator
    finalize(() =>
      // this.store.dispatch(setLoadingSpinner({ showLoading: false }))
      console.log('rdy')
    )
  )
  .subscribe();

可运行的示例:
https://stackblitz.com/edit/edit/redit/rxjs-t5mzxy?file= index。 TS

Just remove shipmentData as argument from your map function, its already there:

import {
  of,
  map,
  Observable,
  from,
  filter,
  tap,
  concatMap,
  forkJoin,
  catchError,
  finalize,
} from 'rxjs';

// Open the console in the bottom right to see results.
function getShipment(x) {
  return new Promise(function (res, rej) {
    res({ key: 'hi, im shipmentData', ShipmentId: 989 });
  });
}

function getOrderLineAllocationByCardIdObservable(x) {
  return of(1);
}

function getLotsByCardIdObservable(x) {
  return of(2);
}

from(getShipment(1))
  .pipe(
    filter((shipmentData) => shipmentData != undefined),
    tap((shipmentData: any) => {
      if (shipmentData.ShipmentId === null || shipmentData.ShipmentId === '') {
        throw 'Shipment needs to be connected';
      }
    }),
    concatMap((shipmentData) =>
      forkJoin(
        getOrderLineAllocationByCardIdObservable(666),
        getLotsByCardIdObservable(666)
      ).pipe(
        filter((response) => response != undefined),
        map(([inventoryData, lotsData]) => {
          console.log(shipmentData);
        })
      )
    ),
    // Catch errors thrown above
    catchError((error) => {
      return of();
    }),
    // Always finish by Hiding Loading indicator
    finalize(() =>
      // this.store.dispatch(setLoadingSpinner({ showLoading: false }))
      console.log('rdy')
    )
  )
  .subscribe();

runnable example:
https://stackblitz.com/edit/rxjs-t5mzxy?file=index.ts

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文