Skip to content

Commit d86d080

Browse files
authored
Merge pull request #13 from FallingCeilingS/v0.1.3/type-emit
Type emit
2 parents 68e256f + a85f979 commit d86d080

File tree

9 files changed

+774
-45
lines changed

9 files changed

+774
-45
lines changed

README.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[![license](https://img.shields.io/npm/l/vue-virtualised.svg?style=flat)](LICENSE)
55
[![vue3](https://img.shields.io/badge/vue-3.x-brightgreen.svg)](https://v3.vuejs.org/)
66
[![npm type definitions](https://img.shields.io/npm/types/vue-virtualised)](https://www.typescriptlang.org/)
7+
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
78

89
> Vue components developed by [Vue.js 3.0](https://v3.vuejs.org/) for efficiently rendering large scrollable lists and hierarchical data. `vue-virtualised` is able to render and update 1 million nodes within a few seconds in front-end.
910
@@ -74,6 +75,11 @@ import { VirtualisedTree as Tree } from "vue-virtualised";
7475
## Types
7576

7677
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+
```
7783

7884
## Props
7985

@@ -89,9 +95,9 @@ Here are props that are identical in both `VirtualisedList` and `VirtualisedTree
8995
|initialScrollIndex|`Number`||`0`|The initial scroll index. If this prop is specified, it will override `initialScrollTop` prop.|
9096
|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>|
9197
|tolerance|`Number`||`2`|Padding of nodes outside of the viewport to allow for smooth scrolling.|
92-
|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>|
93-
|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>|
94-
|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>|
95101

96102
### `VirtualisedList` props
97103

@@ -105,7 +111,7 @@ Here are props that are identical in both `VirtualisedList` and `VirtualisedTree
105111
|---|---|:---:|---|---|
106112
|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>|
107113
|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.|
108-
|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.|
109115

110116
## Events
111117

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

164170
```ts
165-
scrollToNode(conditionCallback: Function): void
171+
scrollToNode(conditionCallback: ConditionCallback): void
166172
```
167173

168174
Valid `conditionCallback` should be a function that takes a node as a parameter and returns a `boolean`:
@@ -189,7 +195,7 @@ Forces refresh rendered content.
189195
scrollToHeight(height: number, behaviour: ScrollBehavior): void
190196
```
191197

192-
#### `createNode()`
198+
#### `createNode(): CreateFunction`
193199

194200
```ts
195201
createNode(nodes: Array<Node | NodeModel>, node: NodeModel, path: Array<number>): Promise<void>
@@ -218,10 +224,10 @@ This method creates a single node (node allows contain children) as well as its
218224
const path = [...node.parents, node.index];
219225
```
220226

221-
#### `updateNode()`
227+
#### `updateNode(): UpdateFunction`
222228

223229
```ts
224-
updateNode(nodes: Array<Node>, node: NodeModel, index: number, updateFn: Function): void
230+
updateNode(nodes: Array<Node>, node: NodeModel, index: number, updateFn: UpdateNodeCallback): void
225231
```
226232

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

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

240-
#### `updateNodes()`
246+
#### `updateNodes(): UpdateFunction`
241247

242248
```ts
243-
updateNodes(nodes: Array<Node>, node: NodeModel, index: number, updateFn: Function): void
249+
updateNodes(nodes: Array<Node>, node: NodeModel, index: number, updateFn: UpdateNodeCallback): void
244250
```
245251

246252
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:
@@ -254,7 +260,7 @@ This method can be bound to `cell` slot, which updates a single node in the tree
254260
updateFn(node: NodeModel): NodeModel
255261
```
256262

257-
#### `removeNode()`
263+
#### `removeNode(): RemoveFunction`
258264

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

0 commit comments

Comments
 (0)