1.0.11 • Published 5 months ago

@danielgindi/virtual-list-helper v1.0.11

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

@danielgindi/virtual-list-helper

A full featured dom virtual list

  • Supports custom elements
  • Supports dynamic heights
  • Item height estimations are optional
  • Native scrolling
  • Allows reverting to non-virtual list

Example

The default exported class is VirtualListHelper, which does all the magic.
I really hope to put in an example here soon. PRs are welcome.

Api


VirtualListHelper~Options

PropertyTypeDefaultMeaning
listElementthe main element to operate inside of
hookScrollEventbooleantrueautomatically hook scroll event as needed
countnumber0the item count
virtualbooleantrueis virtual mode on?
estimatedItemHeightnumber20estimated item height
buffernumber5the amount of buffer items to keep on each end of the list
itemHeightEstimatorFnItemHeightEstimatorFunctionan optional function for providing item height estimations
itemElementCreatorFnItemElementCreatorFunctionan optional function for providing fresh item elements (default creates <li />s)
onItemRenderItemRenderFunctiona function for rendering element content based on item index
onItemUnrenderItemUnrenderFunctiona function for freeing resources in an item element

ItemHeightEstimatorFunction

  • Type: function(index: number):(number|undefined)
  • Responsible for generating item height estimations. This is optional.
ArgumentTypeMeaning
indexnumberindex of the item to get an estimate for
returnnumber, undefinedthe estimation, or undefined to use default estimate

ItemElementCreatorFunction

  • Type: function():Element
  • Responsible for generating item element (regardless of specific item contents!).
  • The default creates and <li> element.
ArgumentTypeMeaning
returnElementthe element to serve as the item

ItemRenderFunction

  • Type: function(itemEl: Element, index: number)
  • Responsible for rendering an item's contents. If you bind any resources that should be deallocated or unbound, you can do so in the ItemUnrenderFunction.
ArgumentTypeMeaning
itemElElementthe element in which to render the item contents
indexnumberthe index of the item

ItemUnrenderFunction

  • Type: function(itemEl: Element)
  • Responsible for cleaning stuff up after an element. Specifically unbinding events or other native resources that were captured during ItemRenderFunction.
  • The elements will always be cleared automatically from child elements regardless of what you do in ItemRenderFunction.
ArgumentTypeMeaning
itemElElementthe element in which to un-render the item contents

VirtualListHelper

This class' api is pretty much self explanatory, but I'll try to find the time to document it properly and add examples.

Me

  • Hi! I am Daniel Cohen Gindi. Or in short- Daniel.
  • danielgindi@gmail.com is my email address.
  • That's all you need to know.

Help

If you want to help, you could:

  • Actually code, and issue pull requests
  • Test the library under different conditions and browsers
  • Create more demo pages
  • Spread the word
  • Donate

License

All the code here is under MIT license. Which means you could do virtually anything with the code. I will appreciate it very much if you keep an attribution where appropriate.

The MIT License (MIT)

Copyright (c) 2013 Daniel Cohen Gindi (danielgindi@gmail.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1.0.11

5 months ago

1.0.10

5 months ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago