employeeChanged: Subject<any> = new Subject<any>();
setInterval(() => {
this.employeeChanged.next(1);
this.employeeChanged.next(1);
this.employeeChanged.next(2);
this.employeeChanged.next(2);
this.employeeChanged.next(3);
this.employeeChanged.next(3);
},1000);
this.employeeChanged.pipe(debounceTime(1000),distinctUntilChanged()).subscribe(((key) => {
console.log(`Employee update: ${key}`);
}));
My example looks like this. I want to get latest value by key that i provide to subject observable so my output looks like this
Employee update: 1
Employee update: 2
Employee update: 3
Which operator i need to use to achieve that?