2.3.0 • Published 7 years ago

unendlich v2.3.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

unendlich

Development sponsored by voltra.co build status

Infinite scrolling component that works with any DOM structure and loads content lazily.

Usage

There needs to be an outer and an inner element, the outer element having

  • a fixed height
  • overflow auto
  • position relative

The rest is up to you:

const Unendlich = require('unendlich')
const html = require('bel')

const rows = []
for (let i = 0; i < 1e5; i++) {
  rows.push({
    foo: String(new Date()),
    bar: 'beep',
    beep: Math.random().toString(16).slice(2)
  })
}

const inner = html`<div></div>`
const outer = html`<ul style="height: 800px; width: 600px; overflow: auto">${inner}</ul>`
document.body.appendChild(outer)

const example = new Unendlich({
  rows,
  inner,
  outer,
  render: row => html`<li>${row.foo}: ${row.bar} (${row.beep})</li>`,
  page: 100,
  padding: 50
})

Async support

A row element can also by an async function, which will then be resolved before rendering:

const rows = [
  async () => fetch(url)
]

Installation

$ npm install unendlich

API

new Unendlich({ rows, inner, outer, render, update, page = 100, padding = 50, rowHeight, debug = false })

Create a new instance and .render() it.

For extra performance, pass update which takes existing old row elements and updates them, instead of creating new ones. For example:

{
  render: row => html`<li>${row.foo}: ${row.bar} (${row.beep})</li>`,
  update: (row, el) => el.innerHTML = `${row.foo}: ${row.bar} (${row.beep})`
}

Unendlich#render({ refresh })

Force a render, if reset is true it will also rerender already rendered rows.

Unendlich#setRows(rows)

Update the row content. Doesn't trigger a rerender by itself.

Unendlich#setHeight(height, { render = true })

Update the #outer element's height. Example: unendlich.setHeight('200px').

License

MIT

2.3.0

7 years ago

2.2.0

7 years ago

2.1.0

7 years ago

2.0.0

7 years ago

1.9.3

7 years ago

1.9.2

7 years ago

1.9.1

7 years ago

1.9.0

7 years ago

1.8.0

7 years ago

1.7.4

7 years ago

1.7.3

7 years ago

1.7.2

7 years ago

1.7.1

7 years ago

1.7.0

7 years ago

1.6.0

7 years ago

1.5.2

7 years ago

1.5.1

7 years ago

1.5.0

7 years ago

1.4.2

7 years ago

1.4.1

7 years ago

1.4.0

7 years ago

1.3.2

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago