Stats Collector Reference Source Repository
import BaseStats from 'stats-collector/lib/stats/BaseStats'
public class | source

BaseStats

A stat collector that initially includes no collector functions.

Example:

const stats = new BaseStats();
stats.addCollector({name: 'custom', initialValue: 0, requirements: [], handleUpdate: fn});
stats.processAll([1, 2, 3, 4, 5]);
stats.get();

Constructor Summary

Public Constructor
public

Method Summary

Public Methods
public

Add a collector function that can process data when process() or get() is called.

public

addFilter(filter: *)

public

addIgnore(name: *)

public

get(zeroForUndefined: *): *

public

process(value: *)

public

processAll(arr: *)

public

reset()

Public Constructors

public constructor source

Public Methods

public addCollector(collector: Object): undefined source

Add a collector function that can process data when process() or get() is called.

Params:

NameTypeAttributeDescription
collector Object

An object with the following properties:

  • name - [String] The name of the collector
  • initialValue - [any] The initial value if update() has never been called
  • requirements - [Array] An array of collector names that must be added before this collector
  • handleProcess - [Function]
  • handleGet - [Function]

Return:

undefined

Example:

const stats = new BaseStats();
stats.addCollector({
  name: 'test-sum',
  initialValue: 0,
  requirements: [],
  handleUpdate: function (prev, state, val) { return prev + val; }
});

public addFilter(filter: *) source

Params:

NameTypeAttributeDescription
filter *

public addIgnore(name: *) source

Params:

NameTypeAttributeDescription
name *

public get(zeroForUndefined: *): * source

Params:

NameTypeAttributeDescription
zeroForUndefined *

Return:

*

public process(value: *) source

Params:

NameTypeAttributeDescription
value *

public processAll(arr: *) source

Params:

NameTypeAttributeDescription
arr *

public reset() source