0.6.0 • Published 5 years ago
floodplains v0.6.0
Floodplains
A small event library.
Includes emit and on.
Demo
Install
npm install floodplainsHow to Use
import Floodplains from "floodplains";
const floodplains = new Floodplains;
floodplains.on("some-event", function (val) {
console.log("some-event", val);
});
floodplains.on("another-event", function (val) {
console.log("another-event", val);
});
floodplains.on(["some-event", "another-event"], function (val) {
console.log("two events:", val);
});
floodplains.on("*", function (val) {
console.log("all events:", val);
});
floodplains.emit("some-event", "hello, world!");
floodplains.emit("another-event", "kittens!");
floodplains.emit("one-more-event", {name: "James"});How it Works
emit
floodplains.emit("some-event", "hello, world!");An emitted event requires a name (e.g. "some-event") and a value (e.g. "hello, world!"). The name must be a string and the value can be anything.
on
floodplains.on("some-event", function (val) {
console.log("some-event", val);
});The on method actively listens for an event with a particular name (e.g. "some-event") and calls its callback whenever an event with that name is emitted.
Special "*" event name will listen to all events.
License
MIT