Skip to content

Commit a85f979

Browse files
committed
Update document
1 parent 8063e44 commit a85f979

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

README.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ import { VirtualisedTree as Tree } from "vue-virtualised";
7575
## Types
7676

7777
A static type system can help prevent many potential runtime errors as applications grow, which is why this project is written in TypeScript. When the documentation is referred to any specific type, please check [types](src/types) folder for more information.
78+
For TypeScript project, types can be imported directly from the library. For example:
79+
80+
```ts
81+
import type { Node, NodeModel } from "vue-virtualised";
82+
```
7883

7984
## Props
8085

@@ -90,9 +95,9 @@ Here are props that are identical in both `VirtualisedList` and `VirtualisedTree
9095
|initialScrollIndex|`Number`||`0`|The initial scroll index. If this prop is specified, it will override `initialScrollTop` prop.|
9196
|scrollBehaviour|`String`||`auto`|Inherited from [`ScrollToOptions.behavior`](https://developer.mozilla.org/en-US/docs/Web/API/ScrollToOptions/behavior) that specifies whether the scrolling should animate smoothly, or happen instantly in a single jump. Value is an enum, which can be one of the following: <ul><li>`smooth`: The scrolling animates smoothly.</li><li>`auto`: The scrolling happens in a single jump. </li></ul>|
9297
|tolerance|`Number`||`2`|Padding of nodes outside of the viewport to allow for smooth scrolling.|
93-
|getNodeHeight|`Function`||`(node) => 40`|A function that takes the current node as a parameter, and returns the height (px) of the node. <div>e.g. `(node) => 30 + (node.index % 10)`</div>|
94-
|getNodeKey|`Function`|||A function that takes the current node and the index of the node in the virtual scroller as parameters, and returns the key of the node. Key is a unique identifier for the virtualised scroller. <div>e.g. `(node, index) => node.key`</div>|
95-
|cellRenderer|`Function`|||A function that takes the current node and its current index in the virtualised scroller as parameters, and returns an array of Children VNodes, built using [`h()`](https://v3.vuejs.org/guide/render-function.html#h-arguments), or using strings to get "text VNodes" or an object with slots. If this prop is specified, the `cell` slot in the template will be override. <div>e.g. `(node, index) => [h("div", {style: {height: "100%"}}, node.name)]`</div>|
98+
|getNodeHeight|`GetNodeHeight`||`(node) => 40`|A function that takes the current node as a parameter, and returns the height (px) of the node. <div>e.g. `(node) => 30 + (node.index % 10)`</div>|
99+
|getNodeKey|`GetNodeKey`|||A function that takes the current node and the index of the node in the virtual scroller as parameters, and returns the key of the node. Key is a unique identifier for the virtualised scroller. <div>e.g. `(node, index) => node.key`</div>|
100+
|cellRenderer|`CellRenderer`|||A function that takes the current node and its current index in the virtualised scroller as parameters, and returns an array of Children VNodes, built using [`h()`](https://v3.vuejs.org/guide/render-function.html#h-arguments), or using strings to get "text VNodes" or an object with slots. If this prop is specified, the `cell` slot in the template will be override. <div>e.g. `(node, index) => [h("div", {style: {height: "100%"}}, node.name)]`</div>|
96101

97102
### `VirtualisedList` props
98103

@@ -106,7 +111,7 @@ Here are props that are identical in both `VirtualisedList` and `VirtualisedTree
106111
|---|---|:---:|---|---|
107112
|nodes|`Array<Node>`|||Tree data with implementing the following keys: <ul><li>`name`: The primary label for the node.</li><li>`state?`: An object stores states of each node.<ul><li>`expanded?`: shows children of the node if `true`, or hides them if `false`. Defaults to `false`.</li></ul></li><li>`children`: An array of child nodes belonging to the node.</li></ul><div>e.g. `[{name: "Node 1", children: [{name: "Leaf 1"}]}, {name: "Node 2"}]`</div>|
108113
|useTimeSlicing|`boolean`||`false`|Time slicing is a technique allows for switching between macro tasks (i.e. DOM redrawing) and micro tasks (i.e. node updating inside an iteration) when traversing and manipulating enormous amount of nodes. If it's set to `true`, we can avoid blocking the whole web application during the process. However, the total amount of traversal time will be longer because the application will switch between macro and micro tasks.|
109-
|onChange|`Function`|||A function that takes `nodes` prop as a parameter. This function will be called when executing `updateNode()` and `updateNodes()` methods.|
114+
|onChange|`OnChangeCallback`|||A function that takes `nodes` prop as a parameter. This function will be called when executing `updateNode()` and `updateNodes()` methods.|
110115

111116
## Events
112117

@@ -163,7 +168,7 @@ Valid `index` should be in the range from `0` to `nodes.length - 1`.
163168
#### `scrollToNode()`
164169

165170
```ts
166-
scrollToNode(conditionCallback: Function): void
171+
scrollToNode(conditionCallback: ConditionCallback): void
167172
```
168173

169174
Valid `conditionCallback` should be a function that takes a node as a parameter and returns a `boolean`:
@@ -190,7 +195,7 @@ Forces refresh rendered content.
190195
scrollToHeight(height: number, behaviour: ScrollBehavior): void
191196
```
192197

193-
#### `createNode()`
198+
#### `createNode(): CreateFunction`
194199

195200
```ts
196201
createNode(nodes: Array<Node | NodeModel>, node: NodeModel, path: Array<number>): Promise<void>
@@ -219,10 +224,10 @@ This method creates a single node (node allows contain children) as well as its
219224
const path = [...node.parents, node.index];
220225
```
221226

222-
#### `updateNode()`
227+
#### `updateNode(): UpdateFunction`
223228

224229
```ts
225-
updateNode(nodes: Array<Node>, node: NodeModel, index: number, updateFn: Function): void
230+
updateNode(nodes: Array<Node>, node: NodeModel, index: number, updateFn: UpdateNodeCallback): void
226231
```
227232

228233
This method can be bound to the `cell` slot, which updates a single node in both original data and the view. Valid parameters are:
@@ -238,10 +243,10 @@ updateFn(node: NodeModel): NodeModel
238243

239244
This method can be used to expand/collapse the current node by setting the boolean value of `state.expanded`.
240245

241-
#### `updateNodes()`
246+
#### `updateNodes(): UpdateFunction`
242247

243248
```ts
244-
updateNodes(nodes: Array<Node>, node: NodeModel, index: number, updateFn: Function): void
249+
updateNodes(nodes: Array<Node>, node: NodeModel, index: number, updateFn: UpdateNodeCallback): void
245250
```
246251

247252
This method can be bound to `cell` slot, which updates a single node in the tree view including all its descendants in both original data and the view. Valid parameters are:
@@ -255,7 +260,7 @@ This method can be bound to `cell` slot, which updates a single node in the tree
255260
updateFn(node: NodeModel): NodeModel
256261
```
257262

258-
#### `removeNode()`
263+
#### `removeNode(): RemoveFunction`
259264

260265
```ts
261266
removeNode(nodes: Array<Node | NodeModel>, path: Array<number>): Promise<void>

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export {
1919
Node,
2020
GetNodeHeight,
2121
GetNodeKey,
22+
CellRenderer,
2223
ConditionCallback,
2324
OnChangeCallback,
2425
} from "@/types/types";

0 commit comments

Comments
 (0)