3.0.1 • Published 6 years ago

lazy-aggregator v3.0.1

Weekly downloads
52
License
ISC
Repository
github
Last release
6 years ago

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

3.0.1

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0-b

6 years ago

1.1.0-a

6 years ago

1.1.0

6 years ago

1.0.2-b

6 years ago

1.0.2-a

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago