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