javascript - 将数组中的管道与 Angular Observable 组合起来

标签 javascript angular rxjs observable

我有 Observable,我将其通过管道传输到多个管道,如下所示。

getOrders(filters: any, page: any = 1, orderBy: string = 'deliver_on', sort: string = 'asc') {

  const opCityPipe = pipe(
    filter((obj: any) => obj.payload.order.op_city_id === 1)
  );

  const storeRefPipe = pipe(
    filter((obj: any) => obj.payload.order.store.ref.match(/^Your.*/))
  );

  const statusPipe = pipe(
    filter((obj: any) => ['assign_request', 'accepted', 
    'in_store', 'en_route_to_client', 'arrived', 
    'canceled'].indexOf(obj.payload.order.status) !== -1)
  );

  return Observable.create((observer: Observer<any>) => {
     this.socket.on('private-order.status.changed.1:order.status', 
     (obj: any) => {
       observer.next(obj);
     });
  }).pipe(opCityPipe, storeRefPipe, statusPipe);
}

如何将管道设置为数组?我想动态填充它。我尝试添加数组但出现错误。

ERROR TypeError: Object(...)(...) is not a function

我想做类似的事情

const pipes = [opCityPipe, storeRefPipe, statusPipe];
Observable.pipe(pipes);

更新解决方案

Observable.pipe(...pipes);

最佳答案

我认为这应该可行,但您收到的错误尚不清楚。

getOrders(filters: any, page: any = 1, orderBy: string = 'deliver_on', sort: string = 'asc') {

  const opCityPipe = filter((obj: any) => obj.payload.order.op_city_id === 1);

  const storeRefPipe = filter((obj: any) => obj.payload.order.store.ref.match(/^Your.*/));

  const statusPipe = filter((obj: any) => ['assign_request', 'accepted', 
    'in_store', 'en_route_to_client', 'arrived', 
    'canceled'].indexOf(obj.payload.order.status) !== -1);
   
  const filters = [opCityPipe, storeRefPipe, statusPipe]

  return Observable.create((observer: Observer<any>) => {
     this.socket.on('private-order.status.changed.1:order.status', 
     (obj: any) => {
       observer.next(obj);
     });
  }).pipe(...filters);
}

关于javascript - 将数组中的管道与 Angular Observable 组合起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55595368/

相关文章:

c# - .Net Core 3.0 Angular SSR 项目未运行

events - Angular2 点击事件未触发

angular - matches.slice 不是一个函数 ng2-bootstrap typeahead

JavaScript 表格不显示

javascript - 我如何在 python django 中使用 REST 来执行多个任务

javascript - 重试后如何获取catchWhen?

reactjs - Reactjs 和 Rxjs 有什么区别?

javascript - RXJS:属性 animationFrame 在 typeof Scheduler 上不存在

javascript - firefox 双击选定文本时如何删除结束空格

javascript - AmCharts 4 处理空数据