0.3.0 • Published 4 years ago

vist v0.3.0

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

vist

Virtual-list component build with react and rxjs

NPM

Selling Point

Vist won't create or remove any DOM when you scroll the list, it will reuse the existing DOM and only change their position and data. But when you resize your window, you'll find the DOM's number is changed, so your virtual list will always have just right number of DOM.

Install

npm install --save vist

Usage

import React from 'react';
import { VirtualList } from 'vist';

class App extends Component {
  constructor(props) {
    super(props);

    const data = new Array(5000).fill(0).map((_, i) => i);

    this.state = {
      data: of(data)
    };
  }

  render() {
    return (
      <VirtualList
        data$={this.state.data}
        options$={of({ height: 60 })}
        style={{ height: 400, border: '1px solid black' }}>
        {(item, index) => (
          <p style={{ height: 59, margin: 0, borderBottom: '1px solid green' }}>
            No. {index} - {item}
          </p>
        )}
      </VirtualList>
    );
  }
}

Props

PropertyTypeDescription
data$Observable<any>Data source of the list.
options$Observable<IVirtualListOptions>Options of the virtual list.
style{[key: string]: string|number}Style of VirtualList container.
classNamestringclassName of VirtualList container.
keepDombooleanDetermine whether to reuse the dom.
uniqKeystringThe key field of list to identify.

IVirtualListOptions

PropertyTypeDefaultDescription
heightnumberNOT NULLItem height, it's necessary, vist use this property to calculate how many rows should be rendered actually.
sparenumber3Spare rows out of the view.
stickybooleantrueWhether the scrollTop need to stick to the container's top when the data is changed or not.
startIndexnumber0To indicate this start index of the list, and the list will scroll to this start index position when mounted.
resizebooleantrueTo mark if the real dom number should be recomputed when the window resize.

License

MIT © musicq

0.3.0

4 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago