scrollWaiter.ts 499 B

1234567891011121314151617181920212223
  1. // see https://github.com/vuejs/vue-router-next/blob/master/playground/scrollWaiter.ts
  2. class ScrollQueue {
  3. private resolve: (() => void) | null = null;
  4. private promise: Promise<any> | null = null;
  5. add() {
  6. this.promise = new Promise((resolve) => {
  7. this.resolve = resolve;
  8. });
  9. }
  10. flush() {
  11. this.resolve && this.resolve();
  12. this.resolve = null;
  13. this.promise = null;
  14. }
  15. async wait() {
  16. await this.promise;
  17. }
  18. }
  19. export const scrollWaiter = new ScrollQueue();