virtua 0.33.5 → 0.33.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.
@@ -1,6 +1,7 @@
1
1
  <script lang="ts">
2
+ import { afterUpdate, onDestroy } from "svelte";
2
3
  import { isRTLDocument, type ItemResizeObserver } from "./core";
3
- import { effect, styleToString } from "./utils";
4
+ import { styleToString } from "./utils";
4
5
 
5
6
  export let index: number;
6
7
  export let offset: number;
@@ -10,11 +11,16 @@
10
11
 
11
12
  let elementRef: HTMLDivElement;
12
13
 
14
+ let cleanupResizer: (() => void) | undefined;
13
15
  // The index may be changed if elements are inserted to or removed from the start of props.children
14
16
  let prevIndex: number | undefined;
15
- effect(() => {
17
+ afterUpdate(() => {
16
18
  if (prevIndex === index) return;
17
- return resizer(elementRef, (prevIndex = index));
19
+ if (cleanupResizer) cleanupResizer();
20
+ cleanupResizer = resizer(elementRef, (prevIndex = index));
21
+ });
22
+ onDestroy(() => {
23
+ if (cleanupResizer) cleanupResizer();
18
24
  });
19
25
 
20
26
  let style: string;
@@ -25,7 +25,7 @@
25
25
  SCROLL_TO_INDEX,
26
26
  } from "./core";
27
27
  import {
28
- effect,
28
+ onUpdate,
29
29
  type UnwrapCustomEvents,
30
30
  defaultGetKey,
31
31
  styleToString,
@@ -131,20 +131,20 @@
131
131
  });
132
132
 
133
133
  let prevLength = data.length;
134
- effect(() => {
134
+ onUpdate(() => {
135
135
  if (prevLength === data.length) return;
136
136
  virtualizer[CHANGE_ITEM_LENGTH]((prevLength = data.length), shift);
137
137
  }, true);
138
138
 
139
139
  let prevJumpCount: number | undefined;
140
- effect(() => {
140
+ onUpdate(() => {
141
141
  if (prevJumpCount === jumpCount) return;
142
142
  prevJumpCount = jumpCount;
143
143
  virtualizer[FIX_SCROLL_JUMP]();
144
144
  });
145
145
 
146
146
  let prevRange: typeof range | undefined;
147
- effect(() => {
147
+ onUpdate(() => {
148
148
  if (prevRange && prevRange[0] === range[0] && prevRange[1] === range[1])
149
149
  return;
150
150
  prevRange = range;
@@ -1,5 +1,5 @@
1
1
  // @ts-nocheck
2
- export declare const effect: (cb: () => (() => void) | void, before?: boolean) => void;
2
+ export declare const onUpdate: (cb: () => void, before?: boolean) => void;
3
3
  export declare const styleToString: (obj: Record<string, string>) => string;
4
4
  export declare const defaultGetKey: (_data: unknown, i: number) => string;
5
5
  /**
@@ -1,14 +1,7 @@
1
- import { afterUpdate, beforeUpdate, onDestroy } from "svelte";
2
- export const effect = (cb, before) => {
3
- let cleanup;
1
+ import { afterUpdate, beforeUpdate } from "svelte";
2
+ export const onUpdate = (cb, before) => {
4
3
  (before ? beforeUpdate : afterUpdate)(() => {
5
- if (cleanup)
6
- cleanup();
7
- cleanup = cb();
8
- });
9
- onDestroy(() => {
10
- if (cleanup)
11
- cleanup();
4
+ cb();
12
5
  });
13
6
  };
14
7
  export const styleToString = (obj) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "virtua",
3
- "version": "0.33.5",
3
+ "version": "0.33.6",
4
4
  "description": "A zero-config, fast and small (~3kB) virtual list (and grid) component for React, Vue, Solid and Svelte.",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.mjs",