2.0.1 • Published 5 years ago
brainlet v2.0.1
brainlet
Introduction
A low-level simple event engine for JS web apps.
Status
This project is being continually maintained.
Installing
npm i brainlet --save
Basic use
import brainlet from 'brainlet';
// You define the events in your app
const eventNames = {
SomeEvent: 'SomeEvent'
};
// This is a basic subscriber function
function subscriber(eventName, data) {
console.log(eventName);
}
// Subscribe the above function
brainlet.subscribe(eventNames.SomeEvent, subscriber);
// Raise an event. This will call all subscribers for the SomeEvent event
brainlet.invokeEvent(eventNames.SomeEvent, { message: 'Hooray' });
// Don't forget to unsubscribe and clean up when you're done
brainlet.unsubscribe(eventNames.SomeEvent, subscriber);
// brainlet also caches event data, which can be retrieved as follows
const someEvent = brainlet.getCachedEventData(eventNames.SomeEvent);
NPM commands
The following can be run with npm run
.
build-dev
: Build the development version ofbrainlet
.build-prod
: Build the production version ofbrainlet
.start
: Runs webpack in watch mode.test
: Runs the tests.lint
: Lints the code.