1.0.3 • Published 7 years ago

thingHolder v1.0.3

Weekly downloads
5
License
ISC
Repository
-
Last release
7 years ago

ThingHolder

Description

ThingHolder object holds a tagged set of things. As each thing is added to the ThingHolder, the ThingHolder emits an 'add' event with the tag name and length of the added thing. The ThingHolder ignores attempts to add things with invalid tags. The contructor takes an array of tags (strings) which represent the valid tags of interest; when a thing for every valid tag has been received, the collection is complete and the ThingHolder emits a 'complete' event with a string announcing that fact.

Usage

 var ThingHolder = require('./thingHolder');
 
 var tags = ['a', 'b', 'c'];
 var collector = new ThingHolder(tags);
 
 collector.on('add', function onAdd(ev) {
     console.log('Added something %s', ev);
 })
 
 collector.on('invalidTag', function onInvalidTag(ev) {
     console.log('Ignored attempt to add thing for invalid tag %s', ev);
 })
 
 collector.on('complete', function onComplete(ev) {
     console.log('Complete: %s', ev);
     console.log(JSON.stringify(collector.things, null, 2));
 })
 
 collector.add('a', "This is an A");
 collector.add('b', "This is an B");
 collector.add('d', "This is an D");
 collector.add('c', "This is an C");

 console.log("We collected (%s) for tag 'a'", collector.thing('a'));
1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago