0.5.1 • Published 5 years ago

@plasma-js/hades v0.5.1

Weekly downloads
6
License
MIT
Repository
github
Last release
5 years ago

Hades

A library for data/event handling

Quickstart

Install:

npm install --save @plasma-js/hades

Then:

// const Hades = require('hades').default;
import Hades from 'hades';

const hades = new Hades();

Usage:

Event manager:

const eventName = 'eventExemple';
const eventHandler = function(message) {
  alert(message);
}

// Subscribe
hades.on(eventName, eventHandler);

// Trigger
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
    }
  ]
};

// Collection register
hades.collections.new(collectionName, collectionFields);

// Validate a entry before register a new line collection
let validEntry = await hades.collections.events.validate(dataExemple);

Tips:

You can import the data managing only (Collections), like in the exemple bellow:

// const Collections = require('hades').Collections;
import { Collections } from 'hades'; // Collections data class

Or only the pubsub class:

// const Events = require('hades').Events;
import { Events } from 'hades'; // Events data class
0.5.1

5 years ago

0.5.0

5 years ago

0.4.6

5 years ago

0.4.5

5 years ago

0.4.0

5 years ago

0.0.1

5 years ago