1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/lib/client-metrics/projection.js

36 lines
758 B
JavaScript
Raw Normal View History

2016-11-04 16:16:55 +01:00
'use strict';
module.exports = class Projection {
2017-06-28 10:17:14 +02:00
constructor() {
2016-11-04 16:16:55 +01:00
this.store = {};
}
2017-06-28 10:17:14 +02:00
getProjection() {
2016-11-04 16:16:55 +01:00
return this.store;
}
2017-06-28 10:17:14 +02:00
add(name, countObj) {
2016-11-04 16:16:55 +01:00
if (this.store[name]) {
this.store[name].yes += countObj.yes;
this.store[name].no += countObj.no;
} else {
this.store[name] = {
yes: countObj.yes,
no: countObj.no,
};
}
}
2017-06-28 10:17:14 +02:00
substract(name, countObj) {
2016-11-04 16:16:55 +01:00
if (this.store[name]) {
this.store[name].yes -= countObj.yes;
this.store[name].no -= countObj.no;
} else {
this.store[name] = {
yes: 0,
no: 0,
};
}
}
2016-11-04 23:09:50 +01:00
};