Skip to content

Commit

Permalink
Merge pull request #11 from FallingCeilingS/v0.1.1/add-invariant-error
Browse files Browse the repository at this point in the history
Add invariant error message for empty nodes props
  • Loading branch information
jchen042 authored Apr 21, 2021
2 parents 9dccf1e + 3cc6503 commit 19be5b4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/components/VirtualisedTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ import {
} from "vue";
import VirtualisedBaseTree from "@/components/Base/VirtualisedBaseTree.vue";
import invariant from "fbjs/lib/invariant";
import isNil from "lodash/isNil";
import {
Node,
OnChangeCallback,
Expand Down Expand Up @@ -108,6 +111,11 @@ export default defineComponent({
},
emits: ["onScroll", "onStartReached", "onEndReached"],
setup(props, { emit }) {
invariant(
!isNil(props.nodes),
`Missing required prop: "nodes". Got ${props.nodes}, but Array<Node> is expected`
);
const virtualisedBaseTree = ref<typeof VirtualisedBaseTree | null>(null);
const key = ref<number>(0);
const createNode = ref<CreateFunction | null>(null);
Expand Down
13 changes: 13 additions & 0 deletions src/examples/simple-example/SimpleExample.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@
</div>
</template>
</virtualised-tree>
<virtualised-tree v-if="selectedComponent === 'VirtualisedTree'">
<template #cell="slotProps">
<!-- node.parents is an array that contains all parent nodes' index -->
<div
:style="{
textAlign: 'left',
marginLeft: `${slotProps.node.parents.length * 30}px`,
}"
>
{{ slotProps.node.name }}
</div>
</template>
</virtualised-tree>
</template>

<script>
Expand Down
8 changes: 4 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createApp } from "vue";
// import SimpleExample from "./examples/simple-example/SimpleExample.vue";
import DemoExample from "./examples/demo-example/DemoExample.vue";
import SimpleExample from "./examples/simple-example/SimpleExample.vue";
// import DemoExample from "./examples/demo-example/DemoExample.vue";

// createApp(SimpleExample).mount("#app");
createApp(DemoExample).mount("#app");
createApp(SimpleExample).mount("#app");
// createApp(DemoExample).mount("#app");

0 comments on commit 19be5b4

Please sign in to comment.