A small event library.
Includes emit
and on
.
npm install floodplains
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"});
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.
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.
MIT