Advertisement
kopyl

rxjs

Mar 24th, 2022
1,362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let keydownBufferSubject$: Subject<frontendNote> = new Subject()
  2.  
  3.         const keydowns$ = fromEvent(document, "keydown").pipe(
  4.             filter((val: any) => val.key !== "Meta")
  5.         )
  6.         this.keydowns$ = keydowns$.subscribe((_) => {
  7.             // console.log(_)
  8.             keydownBufferSubject$.next(this.activeNote)
  9.         })
  10.  
  11.         const keydownBuffer$ = keydownBufferSubject$.pipe(
  12.             scan<any, Array<frontendNote>>((acc, val) => {
  13.                 return [...acc, val]
  14.             }, []),
  15.             debounce((_) => timer(500)),
  16.             take(1),
  17.             mergeAll(),
  18.             distinctUntilKeyChanged("id"),
  19.             repeat()
  20.         )
  21.  
  22.         keydownBuffer$.subscribe((previouslyActiveNote) => {
  23.             this.requests.notes.save.send(previouslyActiveNote)
  24.         })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement