Skip to content

Instantly share code, notes, and snippets.

@andrewarosario
Created December 30, 2020 17:41
Show Gist options
  • Save andrewarosario/72a5d4e1864fcba13ffa75d8f1b3ea6b to your computer and use it in GitHub Desktop.
Save andrewarosario/72a5d4e1864fcba13ffa75d8f1b3ea6b to your computer and use it in GitHub Desktop.
export class AppComponent {
note = new FormControl("");
saveIndicator$ = of("Todas as mudanças foram salvas");
saveCount = 0;
ngOnInit() {
const inputToSave$ = this.note.valueChanges.pipe(
debounceTime(300),
distinctUntilChanged(),
share()
);
const savesInProgress$ = inputToSave$.pipe(
mapTo(of("Salvando...")),
tap(() => this.saveCount++),
);
const savesCompleted$ = inputToSave$.pipe(
mergeMap(value => this.saveChanges(value)),
tap(() => this.saveCount--),
)
inputToSave$.subscribe(console.log);
}
saveChanges(value: string) {
return of(value).pipe(delay(1500));
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment