{"size": 1124, "ext": "js", "max_stars_repo_path": "test.js", "max_stars_repo_name": "mizchi/promised-reducer-combine", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test.js", "max_issues_repo_name": "mizchi/promised-reducer-combine", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test.js", "max_forks_repo_name": "mizchi/promised-reducer-combine", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 33.0588235294, "max_line_length": 89, "alphanum_fraction": 0.6637010676}
'use strict';
const PromisedReducer = require("promised-reducer").default;
const combine = require("./index");

// Usages:
//
// class CombinedReducer<T> extends PromisedReducer<T>
//
// type ReducersMap = {[reducerName]: PromisedReducer};
// function combine<T>(
//   reducersMap: ReducersMap;
//   combineFunc: (rm: ReducersMap) => T
// ): CombinedReducer<T>;

const r1 = new PromisedReducer({a: 1});
const r2 = new PromisedReducer({b: 2});

// async
const composited = combine({r1, r2}, ({r1, r2}) => ({a: r1.a, b: r2.b}));
composited.on(":start-async-updating-by", name => console.log("async started by", name));
composited.on(":end-async-updating-by", name => console.log("async ended by", name));
composited.on(":update", combined => console.log("combined result", combined));
composited.on(":update-by", reducerName => console.log("update fired by", reducerName));

r1.update(s => Promise.resolve({a: s.a + 1}));
r2.update(s => Promise.resolve({b: s.b + 1}));

// async started by r1
// combined result { a: 2, b: 2 }
// update fired by r1
// combined result { a: 2, b: 3 }
// update fired by r2
// async ended by r2
