UNPKG

776 BMarkdownView Raw
1Reduce the view
2---------------
3
4This assumes the view's reducer is `_count`, obviously.
5
6 count_as_stream = (db_uri,app,view,key,detail) ->
7
8 params =
9 reduce: true
10
11 if detail? and Immutable.List.isList key
12 detail = parseInt detail
13 if isNaN(detail) or detail < 0
14 return most.empty()
15
16 params.group_level = key.size + detail
17 params.startkey = JSON.stringify key
18 params.endkey = JSON.stringify key.concat Immutable.Repeat Immutable.Map(), 1
19 else
20 params.key = JSON.stringify key
21 params.group = true
22
23 view_stream db_uri, app, view, params
24
25 module.exports = count_as_stream
26 view_stream = require './view-stream'
27 most = require 'most'
28 Immutable = require 'immutable'