Files: 4caad32bdc583a475ce49a53d2293c67c0f52cb6 / app / html / scroller.js
1255 bytesRaw
1 | const nest = require('depnest') |
2 | const pull = require('pull-stream') |
3 | const Scroller = require('mutant-scroll') |
4 | const next = require('pull-next-step') |
5 | |
6 | exports.gives = nest('app.html.scroller') |
7 | |
8 | exports.needs = nest({ |
9 | 'message.html.render': 'first' |
10 | }) |
11 | |
12 | exports.create = function (api) { |
13 | return nest('app.html.scroller', createScroller) |
14 | |
15 | function createScroller (opts = {}) { |
16 | const { |
17 | stream, |
18 | filter = () => pull.filter((msg) => true), |
19 | indexProperty = ['value', 'timestamp'] |
20 | } = opts |
21 | |
22 | const streamToTop = pull( |
23 | next(stream, {old: false, limit: 100, property: indexProperty }), |
24 | filter() // is a pull-stream through |
25 | ) |
26 | |
27 | const streamToBottom = pull( |
28 | next(stream, {reverse: true, limit: 100, live: false, property: indexProperty }), |
29 | filter() |
30 | ) |
31 | |
32 | return Scroller(Object.assign({}, opts, { streamToTop, streamToBottom })) |
33 | // valid Scroller opts : see github.com/mixmix/mutant-scroll |
34 | // classList = [], |
35 | // prepend = [], |
36 | // append = [], |
37 | // streamToTop, |
38 | // streamToBottom, |
39 | // render, |
40 | // updateTop = updateTopDefault, |
41 | // updateBottom = updateBottomDefault, |
42 | // store = MutantArray(), |
43 | // cb = (err) => { if (err) throw err } |
44 | } |
45 | } |
46 |
Built with git-ssb-web