I'm having an issue with the debounceTime method while trying to prevent multiple requests being sent to the server. The service is currently being called instantly without debouncing.
During a drag and drop event, I need to store positions using the saveWidgetsPosition
function.
drop(event: CdkDragDrop<string[]>) {
if (event.previousContainer !== event.container) {
transferArrayItem(event.previousContainer.data, event.container.data, event.previousIndex, event.currentIndex);
} else {
moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
}
this.saveWidgetsPosition(this.columns);
}
This is the function used to save positions:
saveWidgetsPosition(columns: any[]) {
const columnsLabels = columns.map(x => x.map(y => y.label));
this.userService.saveWidgetsPosition({ user: this.user, columns: columnsLabels})
.pipe(debounceTime(5000))
.subscribe(res => console.log(res));
}