Hades
A library for data/event handling
Quickstart
Install:
npm install --save @plasma-js/hades
Then:
import Hades from 'hades';
const hades = new Hades();
Usage:
Event manager:
const eventName = 'eventExemple';
const eventHandler = function(message) {
alert(message);
}
hades.on(eventName, eventHandler);
hades.publish(eventName, 'Trigger message exemple');
Data manager:
const collectionName = 'events';
const collectionFields = {
name: 'string|required',
location: 'string|required',
tickets: [
{
lote: 'integer|required',
price: 'float|required',
avaiable: 'integer|required'
}
]
};
const dataExemple = {
name: 'Lollapalooza',
location: 'Indie Land',
tickets: [
{
lote: 1,
price: 600.00,
avaiable: 600
},
{
lote: 2,
price: 700.00,
avaiable: 1000
}
]
};
hades.collections.new(collectionName, collectionFields);
let validEntry = await hades.collections.events.validate(dataExemple);
Tips:
You can import the data managing only (Collections), like in the exemple bellow:
import { Collections } from 'hades';
Or only the pubsub class:
import { Events } from 'hades';