commit
bd2721bf8c
14
src/index.js
14
src/index.js
|
@ -1,12 +1,4 @@
|
|||
const EventSyncer = require('./eventSyncer.js')
|
||||
const EventSyncer = require('./eventSyncer.js');
|
||||
EventSyncer.operators = require('./operators');
|
||||
|
||||
const eventSyncer = new EventSyncer(web3);
|
||||
|
||||
eventSyncer.init(() => {});
|
||||
|
||||
// eventSyncer.trackEvent('contractEvent', ((x) => x.from === "0x123")).pipe(map(x => x.rating), myscan, mymap).subscribe((v) => {
|
||||
// console.dir("current average is " + v)
|
||||
// })
|
||||
|
||||
|
||||
// return Event
|
||||
module.exports = EventSyncer;
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
const { of, pipe } = require('rxjs');
|
||||
const { map, pluck, reduce } = require('rxjs/operators');
|
||||
|
||||
function $takeProps() {
|
||||
const args = Object.values(arguments);
|
||||
return pipe(
|
||||
map(v => {
|
||||
const r = {};
|
||||
args.forEach(a => {
|
||||
r[a] = v[a];
|
||||
});
|
||||
return r;
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
// ex 1
|
||||
of({a: 1, b:2, e: 1}, {a: 0, c: 1, b:3}, {a: 0, d: 1, b:1})
|
||||
.pipe($takeProps("a", "b", "e"))
|
||||
.subscribe((v) => console.log(v));
|
||||
*/
|
||||
|
||||
function $average(cb) {
|
||||
return pipe(
|
||||
reduce((accum, curr) => {
|
||||
let currentValue;
|
||||
if (typeof cb === 'string' || cb instanceof String){
|
||||
currentValue = curr[cb];
|
||||
} else if(typeof cb === "function") {
|
||||
currentValue = cb(curr);
|
||||
} else {
|
||||
currentValue = curr;
|
||||
}
|
||||
|
||||
return {
|
||||
sum: accum.sum + currentValue,
|
||||
count: accum.count + 1
|
||||
}
|
||||
}, { sum: 0, count: 0 }),
|
||||
map(o => o.sum / o.count)
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
of(10, 3, 4)
|
||||
.pipe($average())
|
||||
.subscribe((v) => console.log(v));
|
||||
*/
|
||||
|
||||
|
||||
module.exports = {
|
||||
$takeProps,
|
||||
$average
|
||||
};
|
|
@ -2,7 +2,7 @@ const path = require('path');
|
|||
|
||||
const webConfig = {
|
||||
target: 'web',
|
||||
entry: path.join(__dirname, "src/eventSyncer.js"),
|
||||
entry: path.join(__dirname, "src/index.js"),
|
||||
output: {
|
||||
path: path.resolve(__dirname, "dist"),
|
||||
filename: 'browser.js',
|
||||
|
|
Loading…
Reference in New Issue