Skip to content
This repository was archived by the owner on Nov 5, 2023. It is now read-only.

Commit 0ba9ce4

Browse files
committed
feat: export all items memoized by the grid
1 parent a1d5067 commit 0ba9ce4

File tree

3 files changed

+28
-23
lines changed

3 files changed

+28
-23
lines changed

README.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,6 @@ npm install vue-virtual-scroll-grid
4343
| `tag` | The HTML tag used as container element. Default value is `div` | `string` | Optional, any valid HTML tag, defaults to `div` |
4444
| `getKey` | The `:key` used on each grid item. Auto-generated, but overwritable via function | `(internalItem: InternalItem) => number \| string` <sup>1</sup>| Optional, any valid Function that returns a `string` or `number` |
4545

46-
<sup>1</sup>
47-
```ts
48-
interface InternalItem {
49-
index: number;
50-
value: unknown | undefined;
51-
style?: { transform: string; gridArea: string };
52-
}
53-
```
54-
5546
Example:
5647

5748
```vue
@@ -127,6 +118,10 @@ Example:
127118
</template>
128119
```
129120

121+
## Exposed Public Properties
122+
123+
* `allItems`: All items memoized by the grid
124+
130125
## Scroll Mode
131126

132127
The library uses `grid-auto-flow` CSS property to infer scroll mode. Set it to

src/Grid.vue

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export default defineComponent({
122122
default: undefined,
123123
},
124124
},
125-
setup(props) {
125+
setup(props, { expose }) {
126126
// template refs
127127
const rootRef = ref<HTMLElement | SVGElement | VueInstance>();
128128
const probeRef = ref<HTMLElement | SVGElement | VueInstance>();
@@ -132,6 +132,7 @@ export default defineComponent({
132132
buffer$, // the items in the current scanning window
133133
contentSize$, // the size of the whole list
134134
scrollAction$, // the value sent to window.scrollTo()
135+
allItems$, // all items memoized by the grid
135136
} = pipeline({
136137
// streams of prop
137138
length$: fromProp(props, "length"),
@@ -153,7 +154,7 @@ export default defineComponent({
153154
scrollAction$.subscribe(({ target, top, left }: ScrollAction) => {
154155
target.scrollTo({ top, left, behavior: props.scrollBehavior });
155156
});
156-
})
157+
}),
157158
);
158159
159160
const contentSize = useObservable(contentSize$);
@@ -164,16 +165,19 @@ export default defineComponent({
164165
value + "px",
165166
]),
166167
["placeContent", "start"],
167-
])
168+
]),
168169
);
169170
170171
const keyPrefix = ref<string>("");
171172
watch(
172173
() => props.pageProvider,
173174
() => (keyPrefix.value = String(new Date().getTime())),
174-
{ immediate: true }
175+
{ immediate: true },
175176
);
176177
178+
const allItems = useObservable(allItems$);
179+
expose({ allItems });
180+
177181
return {
178182
rootRef,
179183
probeRef,

src/demo/App.vue

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
<div :class="$style.gridWrapper">
66
<Grid
7+
ref="grid"
78
:length="length"
89
:pageSize="pageSize"
910
:pageProvider="pageProvider"
@@ -45,7 +46,7 @@
4546
</template>
4647

4748
<script lang="ts">
48-
import { defineComponent } from "vue";
49+
import { defineComponent, ref } from "vue";
4950
import Grid from "../Grid.vue";
5051
import Header from "./Header.vue";
5152
import Control from "./Control.vue";
@@ -63,15 +64,20 @@ import {
6364
export default defineComponent({
6465
name: "App",
6566
components: { Grid, ProductItem, Header, Control },
66-
setup: () => ({
67-
length,
68-
pageSize,
69-
pageProvider,
70-
scrollMode,
71-
scrollTo,
72-
scrollBehavior,
73-
respectScrollToOnResize,
74-
}),
67+
setup: () => {
68+
const grid = ref(null);
69+
70+
return {
71+
grid,
72+
length,
73+
pageSize,
74+
pageProvider,
75+
scrollMode,
76+
scrollTo,
77+
scrollBehavior,
78+
respectScrollToOnResize,
79+
};
80+
},
7581
});
7682
</script>
7783

0 commit comments

Comments
 (0)