@teachingtextbooks/event-manager
TypeScript icon, indicating that this package has built-in type declarations

3.3.0 • Public • Published

Event Manager

Installation

npm install @teachingtextbooks/event-manager

Usage

import EventManager from "@teachingtextbooks/event-manager"

const EM = new EventManager();

const callback = (data: any) => {
    console.log("the data:", data);
};

// add event
EM.addEventListener("string name", callback);

// remove event
EM.removeEventListener("string name", callback);

// dispatch event

// method 1 (JSON object with `type`)
EM.dispatchEvent({ type: "string name", lawnColor: "green", garden: ["potatoes", "tomatoes", "carrots"] });

// method 2 (string first parameter, and optional JSON object as the second parameter)
EM.dispatchEvent("string name", { gameCharacters: ["Mario", "Zelda", "Donkey Kong"] });

// alias for those who want to use them
// EM.on, EM.off, and EM.emit

Readme

Keywords

none

Package Sidebar

Install

npm i @teachingtextbooks/event-manager

Weekly Downloads

6

Version

3.3.0

License

ISC

Unpacked Size

9.96 kB

Total Files

6

Last publish

Collaborators

  • freq
  • timbozer
  • randyk14
  • tt-gregory
  • alex-t
  • seangleeson
  • wclarkson
  • tt-developer