68

GitHub - benjvmin/TinyPubSub: A small Publish/Subscribe library for project use!

 6 years ago
source link: https://github.com/benjvmin/TinyPubSub
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

TinyPubSub

An extremely tiny Publish/Subscribe library with a thoughtful debugging process, perfect for project use!

Basic API

Import Events Object

import { Events } from "./modulesFolder/TinyPubSub.js";

Add Events:

Events.add("Event Name", someCallbackFunction);

Remove Events:

Events.remove("Event Name", functionToRemove);

Trigger Events:

Events.emit(someFunctionToTrigger, someDataToPass);

Debugging:

Turn On / Off

Events.debug.on = true;

By default debugging is on (and recommended). When interacting with the Basic API provided, TinyPubSub will notify you via console warnings if you try and add, remove, or emit events that don't exist. This helps reduce errors due to the decoupled nature of TinyPubSub, and helps catch spelling errors.

List All Events

Console.logs all events presently stored.

Events.debug.list();

List a Specific Event

Console.logs a specific event.

Events.debug.listEvent("eventName");

Features:

  • Thoughtful Debugging Process / Debug API

  • Extremely Tiny (953 bytes minified + uglified!)

  • Zero Dependencies

  • Forged from ES6

  • Made with love.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK