Creates aggregation wrapper
npm install lazy-aggregatorCreate lazy-initialized dictionary based on source dictionary handled with fn
Parameters
- source [Object][1]<[string][2], any> dictionary of configs for fn call (optional, default {})
- fn [function][3] function which will be used to create elements in aggregation (optional, default function(key,value){returnvalue})
Examples
``javascript
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][4] if fn is not a function
add element to aggregation
Parameters
- key [String][2] first argument to fnvalue
- any? data for fn call
Examples
`javascript`
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);
aggregationadd;
aggregation.newEl; // 4
Returns [Object][1] this
delete element from aggregation
Parameters
- key [String][2] key of aggregation member to delete
Examples
`javascript``
import Aggregation from 'lazy-aggregator';
import {del} from 'lazy-aggregator';
const fn = (a) => a * 2;
const aggregation = new Aggregation({newEl: 3}, fn);
aggregationdel;
aggregation.newEl; // undefined
Returns [Object][1] this
npm install --save lazy-aggregator
[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error