Files: a683541f27c2757c560090b0fa816b37d947d42f / intermediate / channelV1.js
675 bytesRaw
1 | const flumeView = require('flumeview-reduce') |
2 | |
3 | const NAME = 'channel' |
4 | const VERSION = 1 |
5 | |
6 | module.exports = { |
7 | name: NAME, |
8 | version: VERSION, |
9 | manifest: { |
10 | all: 'async' |
11 | }, |
12 | init: function (server, config) { |
13 | const view = server._flumeUse( |
14 | NAME, |
15 | flumeView(VERSION, reduce, map, null, initialState()) |
16 | ) |
17 | |
18 | return { |
19 | all: view.get |
20 | } |
21 | } |
22 | } |
23 | |
24 | function map (msg) { |
25 | var content = msg.value.content |
26 | return content.channel |
27 | } |
28 | |
29 | // if map returns null or undefined, reduce is skipped |
30 | function reduce (accumulator, channel) { |
31 | accumulator[channel] = (accumulator[channel] || 0) + 1 |
32 | return accumulator |
33 | } |
34 | |
35 | function initialState () { |
36 | return {} |
37 | } |
38 |
Built with git-ssb-web