Expected behavior:
Reset interval when input value changes. When interval reaches 0 hide element in the dom.
My implementation does not consistently restart the interval. I believe the issue is because the value changes observable only fires off when the input value is a distinct values. I have add a Stackblitz to show the behavior. Any help is greatly appreciated.
View
<input [formControl]="inputFC">
Controller
public inputFC: FormControl = new FormControl('', []);
public counter$ = interval(1000).pipe(
mapTo(-1), // subtract from timer
scan((accumulator, current) => {
return accumulator + current;
}, 3),
takeWhile(value => {
return value >= 0;
}),
map(value => {
this.hide = (value >= 0);
return value;
}),
repeatWhen(() => this.inputFC.valueChanges));
public input$ = this.inputFC.valueChanges.pipe(throttle(() => this.counter$));