I have the stream:
this.unselectedObjectsIds$ = this.selectedObjectsIds$.pipe(pairwise());
Where this.selectedObjectsIds$ is
[
['131086', '131089', '131090', '131638', '132139'],
['131086', '131089']
]
I try to apply this fiilter to the stream:
this.unselectedObjectsIds$ = this.selectedObjectsIds$.pipe(
pairwise(),
map((a) => a[0].filter(x => !a[1].includes(x))
);
Filter is:
a[0].filter(x => !a[1].includes(x));
But it does not work for me.
pairwise is waiting for the next value
Because you have only one value - it is array: [['131086', '131089', '131090', '131638', '132139'], ['131086', '131089']]
if selectedObjectsIds$ is BehaviorSubject for example
you need send a new value
selectedObjectsIds$.next([]) and your code will be paired as
[[['131086', '131089', '131090', '131638', '132139'], ['131086', '131089']], []]
I will try to guess what you are going to have in OUTPUT:
is it ["131090", "131638", "132139"]?
if yes - then use next snippet
import { map, pairwise, take, tap } from 'rxjs/operators';
import { BehaviorSubject, interval, of } from 'rxjs';
const selectedObjectsIds$ = new BehaviorSubject([
['131086', '131089', '131090', '131638', '132139'],
['131086', '131089'],
]);
const unselectedObjectsIds$ = selectedObjectsIds$.pipe(
tap((data) => {
console.log(data);
}),
map(([arr1, arr2]) => {
console.log(arr1);
console.log(arr2);
return arr1.filter((x) => !arr2.find((i) => i === x));
})
);
unselectedObjectsIds$.subscribe((data) => console.log(data));
demo: https://stackblitz.com/edit/typescript-i4nazm?file=index.ts