# hyperloadmore

> a simple paginator

Latest version **1.1.0** (published 2017-12-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install hyperloadmore
pnpm add hyperloadmore
yarn add hyperloadmore
bun add hyperloadmore
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2017-12-03 |
| First published | 2017-12-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | 'Dominic Tarr' |
| Maintainers | dominictarr |

## Links

- npm: https://www.npmjs.com/package/hyperloadmore
- Repository: https://github.com/dominictarr/hyperloadmore
- Issues: https://github.com/dominictarr/hyperloadmore/issues
- npm.io page: https://npm.io/package/hyperloadmore

## Dependencies (2)

- [hyperscript](https://npm.io/package/hyperscript.md) ^2.0.2
- [pull-read-queue](https://npm.io/package/pull-read-queue.md) ^1.0.1

## Recent versions

- 1.1.0 (latest) — 2017-12-03
- 1.0.0 — 2017-12-03

## README

# hyperloadmore

a simple paginator

The main goal here is to come up with an interface that could
be supported by both an infinite scroller, or a "load more" button.
some interfaces also like to have a "load more" at the top,
but an infinite scroll at the bottom.

The interface used here is CustomEvents, first `hyperloadmore`
is created with a content object. The user emits "hasmore" messages
on the content element when there are new elements ready to display.
this updates the button to show the user it's waiting.
When the user clicks the button, the `hyperloadmore` emits
a `readymore` event - this tells content to add more elements
to that end... The content is responsible for
deciding how many to add, and if/when there are more to come,
to emit another "hasmore" event.

`hasmore` events have a `.detail.top` and `.detail.bottom` boolean
properties to indicate whether the new content is to be added
at the start or end. ("detail" is a feature of [CustomEvents api](https://davidwalsh.name/customevent))

## scrolling

This is also an idea towards a better infinite scroller. We need to decouple the control part from the application.
I want the incoming data to be decoupled from the thing which manages the scrolling.

## example

``` js
var HyperLoadMore = require('hyperloadmore')

var h = require('hyperscript')

var content = h('content')

content.addEventListener('readymore', function (ev) {
  if(ev.detail.bottom) {
    for(var i = 0; i < 10; i++)
      content.appendChild(createElement(...))
  }
})

document.body.appendChild(HyperLoadMore(content))

content.dispatchEvent(
  new CustomEvent('hasmore', {target: content, detail: {bottom: true, count: 10}})
)
```

## example 2: streams helper

``` js
var HyperLoadMore = require('hyperloadmore')
var Streams = require('hyperloadmore/stream')
var h = require('hyperscript')
var content = h('div.content')

document.body.appendChild(HyperLoadMore(content))

pull(
  source,
  pull.map(render), //turn into an html element
  streams.bottom(content) //stream into the loadmore! that's all!
)
```

## events

### readymore

`event.target` is the element to be added to.
`event.detail.top` is true if elements should be added to the top.
`event.detail.bottom` is true if elements should be added to the bottom

### hasmore

when you have new data ready to display, emit the `hasmore` event.
``` js
content.dispatchEvent(new CustomEvent('hasmore', {
  target: content,
  detail: {
    bottom: true, top: false, //bottom should != top
    count: N //optional.
  }
}))
```

## streams

see also, streams helper

``` js

```

## License

MIT

---
_Source: https://npm.io/package/hyperloadmore · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
