0

I have Observable where I'm piping it to multipe pipes as follows.

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);
}

How can I make the pipe as array? I want to dynamically populate it. I tried to add the array but got an error.

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

I want to do something like

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

UPDATE SOLUTION

Observable.pipe(...pipes);
1
  • can you show the error shown when you tried to add that array ? Commented Apr 9, 2019 at 14:50

1 Answer 1

1

I think this should work, but the error you're getting is not clear.

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);
}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.