Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
inokawa committed Feb 12, 2024
1 parent de574f1 commit 2afc413
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/vue/Virtualizer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { createResizer } from "../core/resizer";
import { createScroller } from "../core/scroller";
import { ScrollToIndexOpts } from "../core/types";
import { ListItem } from "./ListItem";
import { exists } from "../core/utils";
import { getKey } from "./utils";

export interface VirtualizerHandle {
/**
Expand Down Expand Up @@ -199,10 +199,9 @@ export const Virtualizer = /*#__PURE__*/ defineComponent({
i++
) {
const e = slots.default(props.data![i]!)[0]! as VNode;
const key = e.key;
items.push(
<ListItem
key={exists(key) ? key : "_" + i}
key={getKey(e, i)}
_resizer={resizer._observeItem}
_index={i}
_offset={store._getItemOffset(i)}
Expand Down
5 changes: 2 additions & 3 deletions src/vue/WindowVirtualizer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
import { createWindowResizer } from "../core/resizer";
import { createWindowScroller } from "../core/scroller";
import { ListItem } from "./ListItem";
import { exists } from "../core/utils";
import { getKey } from "./utils";

const props = {
/**
Expand Down Expand Up @@ -146,10 +146,9 @@ export const WindowVirtualizer = /*#__PURE__*/ defineComponent({
i++
) {
const e = slots.default(props.data![i]!)[0]! as VNode;
const key = e.key;
items.push(
<ListItem
key={exists(key) ? key : "_" + i}
key={getKey(e, i)}
_resizer={resizer._observeItem}
_index={i}
_offset={store._getItemOffset(i)}
Expand Down
10 changes: 10 additions & 0 deletions src/vue/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { VNode } from "vue";
import { exists } from "../core/utils";

/**
* @internal
*/
export const getKey = (e: VNode, i: number): Exclude<VNode["key"], null> => {
const key = e.key;
return exists(key) ? key : "_" + i;
};

0 comments on commit 2afc413

Please sign in to comment.