lazy-aggregator
v3.0.1
Published
Creates aggregation wrapper
Downloads
186
Readme
lazy-aggregator
Create lazy-initialized dictionary based on source
dictionary handled with fn
Parameters
source
Object<string, any> dictionary of configs forfn
call (optional, default{}
)fn
function function which will be used to create elements in aggregation (optional, defaultfunction(key,value){returnvalue}
)
Examples
import Aggregation from 'lazy-aggregator';
const fn = (a) => a * 2;
const source = { el1: 1, el2: 2};
const aggregation = new Aggregation(source, fn);
aggregation['el1']; // 1
aggregation.el2; // 2
- Throws Error if
fn
is not a function
add
add element to aggregation
Parameters
key
String first argument tofn
value
any? data forfn
call
Examples
import Aggregation from 'lazy-aggregator';
import {add} from 'lazy-aggregator';
const fn = (a) => a * 2;
const source = { el1: 1, el2: 2};
const aggregation = new Aggregation({}, fn);
aggregation[add]('newEl', 2);
aggregation.newEl; // 4
Returns Object this
del
delete element from aggregation
Parameters
key
String key of aggregation member to delete
Examples
import Aggregation from 'lazy-aggregator';
import {del} from 'lazy-aggregator';
const fn = (a) => a * 2;
const aggregation = new Aggregation({newEl: 3}, fn);
aggregation[del]('newEl');
aggregation.newEl; // undefined
Returns Object this
Installation
npm install --save lazy-aggregator