Skip to content

Commit 3cc6503

Browse files
committed
Add invariant error message for empty nodes props
1 parent 9dccf1e commit 3cc6503

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

src/components/VirtualisedTree.vue

+8
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ import {
4444
} from "vue";
4545
import VirtualisedBaseTree from "@/components/Base/VirtualisedBaseTree.vue";
4646
47+
import invariant from "fbjs/lib/invariant";
48+
import isNil from "lodash/isNil";
49+
4750
import {
4851
Node,
4952
OnChangeCallback,
@@ -108,6 +111,11 @@ export default defineComponent({
108111
},
109112
emits: ["onScroll", "onStartReached", "onEndReached"],
110113
setup(props, { emit }) {
114+
invariant(
115+
!isNil(props.nodes),
116+
`Missing required prop: "nodes". Got ${props.nodes}, but Array<Node> is expected`
117+
);
118+
111119
const virtualisedBaseTree = ref<typeof VirtualisedBaseTree | null>(null);
112120
const key = ref<number>(0);
113121
const createNode = ref<CreateFunction | null>(null);

src/examples/simple-example/SimpleExample.vue

+13
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@
4444
</div>
4545
</template>
4646
</virtualised-tree>
47+
<virtualised-tree v-if="selectedComponent === 'VirtualisedTree'">
48+
<template #cell="slotProps">
49+
<!-- node.parents is an array that contains all parent nodes' index -->
50+
<div
51+
:style="{
52+
textAlign: 'left',
53+
marginLeft: `${slotProps.node.parents.length * 30}px`,
54+
}"
55+
>
56+
{{ slotProps.node.name }}
57+
</div>
58+
</template>
59+
</virtualised-tree>
4760
</template>
4861

4962
<script>

src/main.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createApp } from "vue";
2-
// import SimpleExample from "./examples/simple-example/SimpleExample.vue";
3-
import DemoExample from "./examples/demo-example/DemoExample.vue";
2+
import SimpleExample from "./examples/simple-example/SimpleExample.vue";
3+
// import DemoExample from "./examples/demo-example/DemoExample.vue";
44

5-
// createApp(SimpleExample).mount("#app");
6-
createApp(DemoExample).mount("#app");
5+
createApp(SimpleExample).mount("#app");
6+
// createApp(DemoExample).mount("#app");

0 commit comments

Comments
 (0)