lazy-aggregator

3.0.1 • Public • Published

lazy-aggregator

Create lazy-initialized dictionary based on source dictionary handled with fn

Parameters

  • source Object<string, any> dictionary of configs for fn call (optional, default {})
  • fn function function which will be used to create elements in aggregation (optional, default function(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 to fn
  • value any? data for fn 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

/lazy-aggregator/

    Package Sidebar

    Install

    npm i lazy-aggregator

    Weekly Downloads

    202

    Version

    3.0.1

    License

    ISC

    Unpacked Size

    196 kB

    Total Files

    9

    Last publish

    Collaborators

    • a.chepugov