git ssb

0+

mixmix / ssb-testing-guide



Tree: a683541f27c2757c560090b0fa816b37d947d42f

Files: a683541f27c2757c560090b0fa816b37d947d42f / intermediate / channelV1.js

675 bytesRaw
1const flumeView = require('flumeview-reduce')
2
3const NAME = 'channel'
4const VERSION = 1
5
6module.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
24function map (msg) {
25 var content = msg.value.content
26 return content.channel
27}
28
29// if map returns null or undefined, reduce is skipped
30function reduce (accumulator, channel) {
31 accumulator[channel] = (accumulator[channel] || 0) + 1
32 return accumulator
33}
34
35function initialState () {
36 return {}
37}
38

Built with git-ssb-web