import { Subject } from 'rxjs';
import { debounceTime } from 'rxjs/operators';
import { onUnmounted } from 'vue';

export function useDebounce(func: any, time: number) {

  const trigger = new Subject();
  trigger
    .pipe(
      debounceTime(time)
    )
    .subscribe(e => func(e))

  const next = (e: any) => trigger.next(e);
  
  onUnmounted(() => trigger.complete());

  return next
}