I have next rxjs code that checked if query length is > 1 then the rest operators execute:
o$.pipe(
filter((query) => query.length > 1),
distinctUntilChanged(),
switchMap((query) => {
return this.data.query(query);
})
)
.subscribe((data) => {
this.localData = data; //returns array
});
I want to assign this.localData = [] in case if query.length === 0. So thought to use operator like tap() above filter() where I would put that logic, but distinctUntilChanged() braking the logic because in case if cur value is equal to prev value the localData will be lost:
o$.pipe(
filter((query) => query.length > 1),
tap((query) => {
if(query.length === 1) {
this.localData = [];
}
}),
distinctUntilChanged(),
switchMap((query) => {
return this.data.query(query);
})
)
.subscribe((data) => {
this.localData = data; //returns array
});
Any ideas how to fix?