Files: 87dd7388171016a3b49fb155c4b07fd06b4c5436 / app / html / scroller.js
1343 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, // TODO - rename this to createStream (rename across app) |
18 | filter = () => pull.filter((msg) => true), |
19 | indexProperty = ['value', 'timestamp'] |
20 | } = opts |
21 | |
22 | const streamToTop = pull( |
23 | next(stream, { live: true, reverse: false, old: false, limit: 100, property: indexProperty }), |
24 | filter() // is a pull-stream through |
25 | ) |
26 | |
27 | const streamToBottom = pull( |
28 | next(stream, { live: false, reverse: true, limit: 100, 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