1 | Most.js source for a `map` function in a view
|
2 | ---------
|
3 |
|
4 | Maps results from a changes stream into a view
|
5 |
|
6 | The view is evaluated locally (since CouchDB does not support `changes` on views).
|
7 |
|
8 | The `db_changes` stream is generated by e.g. `all_changes`.
|
9 |
|
10 | changes_view = (map_function,db_changes) ->
|
11 | db_changes
|
12 | .chain ({doc}) ->
|
13 |
|
14 | create (add,end,error) ->
|
15 |
|
16 | Emulate a row as reported without `include_docs`, similarly to what `view_as_stream` does.
|
17 |
|
18 | emit = (key,value) ->
|
19 | add {id:doc._id,key,value}
|
20 |
|
21 | fn = map_function emit
|
22 |
|
23 | try
|
24 | fn doc
|
25 | catch e
|
26 | error e
|
27 | end()
|
28 | return
|
29 |
|
30 | {create} = require '@most/create'
|
31 | module.exports = changes_view
|