3.0.1 • Published 7 years ago
lazy-aggregator v3.0.1
lazy-aggregator
Create lazy-initialized dictionary based on source dictionary handled with fn
Parameters
sourceObject<string, any> dictionary of configs forfncall (optional, default{})fnfunction 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
fnis not a function
add
add element to aggregation
Parameters
keyString first argument tofnvalueany? data forfncall
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; // 4Returns Object this
del
delete element from aggregation
Parameters
keyString 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; // undefinedReturns Object this
Installation
npm install --save lazy-aggregator