Is it possible to get the arguments of tap function not nested? like some of those ways:
tap(([foo, bar, baz]) => {
or:
tap((foo, bar, baz) => {
or:
tap(({foo, bar, baz}) => {
Because I using withLatestFrom which give me array and I pass an object into Subject so I wondering if its possible to get the arguments in flat way?
import { of, map, Observable, Subject, tap } from 'rxjs';
import { withLatestFrom } from 'rxjs/operators';
const action = new Subject<{ foo: number; bar: number }>();
const baz$ = of(3);
const op = action.pipe(
withLatestFrom(baz$),
tap(([{ foo, bar }, baz]) => {
console.log({ foo, bar, baz });
})
);
op.subscribe();
action.next({ foo: 1, bar: 2 });
You can create a custom operator to flatten object to array
const transformToArray = source=>source.pipe(map((values:any)=>{
return values.map(v=>v instanceof Object?Object.values(v):v).flat()
}
))
const op = action.pipe(
withLatestFrom(baz$),
transformToArray
);