virtua 0.43.5 → 0.43.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,12 +28,10 @@ const microtask = typeof queueMicrotask === "function"
28
28
  */
29
29
  const createPromise = () => {
30
30
  let resolve;
31
- let reject;
32
- const promise = new Promise((res, rej) => {
31
+ const promise = new Promise((res) => {
33
32
  resolve = res;
34
- reject = rej;
35
33
  });
36
- return [promise, resolve, reject];
34
+ return [promise, resolve];
37
35
  };
38
36
  /**
39
37
  * @internal
@@ -704,7 +702,7 @@ const createScroller = (store, isHorizontal) => {
704
702
  let viewportElement;
705
703
  let scrollObserver;
706
704
  let cancelScroll;
707
- const [initialized, resolveInitialized] = createPromise();
705
+ let initialized = createPromise();
708
706
  const scrollOffsetKey = isHorizontal ? "scrollLeft" : "scrollTop";
709
707
  const overflowKey = isHorizontal ? "overflowX" : "overflowY";
710
708
  // The given offset will be clamped by browser
@@ -713,8 +711,7 @@ const createScroller = (store, isHorizontal) => {
713
711
  // Wait for element assign. The element may be undefined if scrollRef prop is used and scroll is scheduled on mount.
714
712
  // https://github.com/inokawa/virtua/pull/733
715
713
  // https://github.com/inokawa/virtua/pull/750
716
- const ok = await initialized;
717
- if (!ok) {
714
+ if (!(await initialized[0])) {
718
715
  return;
719
716
  }
720
717
  if (cancelScroll) {
@@ -806,11 +803,13 @@ const createScroller = (store, isHorizontal) => {
806
803
  viewport[scrollOffsetKey] += jump;
807
804
  }
808
805
  });
809
- resolveInitialized(true);
806
+ initialized[1](true);
810
807
  },
811
808
  $dispose() {
812
809
  scrollObserver && scrollObserver._dispose();
813
- resolveInitialized(false);
810
+ initialized[1](false);
811
+ // https://github.com/inokawa/virtua/pull/765
812
+ initialized = createPromise();
814
813
  },
815
814
  $scrollTo(offset) {
816
815
  scheduleImperativeScroll(() => offset);
@@ -859,7 +858,7 @@ const createWindowScroller = (store, isHorizontal) => {
859
858
  let containerElement;
860
859
  let scrollObserver;
861
860
  let cancelScroll;
862
- const [initialized, resolveInitialized] = createPromise();
861
+ let initialized = createPromise();
863
862
  const calcOffsetToViewport = (node, viewport, window, isHorizontal, offset = 0) => {
864
863
  // TODO calc offset only when it changes (maybe impossible)
865
864
  const offsetKey = isHorizontal ? "offsetLeft" : "offsetTop";
@@ -877,8 +876,7 @@ const createWindowScroller = (store, isHorizontal) => {
877
876
  // Wait for element assign. The element may be undefined if scrollRef prop is used and scroll is scheduled on mount.
878
877
  // https://github.com/inokawa/virtua/pull/733
879
878
  // https://github.com/inokawa/virtua/pull/750
880
- const ok = await initialized;
881
- if (!ok) {
879
+ if (!(await initialized[0])) {
882
880
  return;
883
881
  }
884
882
  if (cancelScroll) {
@@ -963,12 +961,14 @@ const createWindowScroller = (store, isHorizontal) => {
963
961
  window.scrollBy(isHorizontal ? jump : 0, isHorizontal ? 0 : jump);
964
962
  }
965
963
  }, () => calcOffsetToViewport(container, documentBody, window, isHorizontal));
966
- resolveInitialized(true);
964
+ initialized[1](true);
967
965
  },
968
966
  $dispose() {
969
967
  scrollObserver && scrollObserver._dispose();
970
968
  containerElement = undefined;
971
- resolveInitialized(false);
969
+ initialized[1](false);
970
+ // https://github.com/inokawa/virtua/pull/765
971
+ initialized = createPromise();
972
972
  },
973
973
  $fixScrollJump: () => {
974
974
  scrollObserver && scrollObserver._fixScrollJump();