publer
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

GitHub Workflow Status Codecov GitHub issues GitHub npm npm bundle size

Publer

publer is a tiny, type-safe pubsub library written in typescript.

Installation

npm install publer

Usage

import { publer } from "publer";

type Peer = {
  id: number;
  username: string
}

interface Events {
  login: [email: string; password: string];
  logout: []; // no arguments
  peerConnected: [peer: Peer]
  peerDisconnected: [peer: Peer]
}

const [pub, sub] = publer<Events>();

// returns a cleanup function to remove listener
const unsub = sub("login", (email, password) => {
  // payload is inferred
});

// fails without arguments, must be provided
pub("login", 'john@doe.com', 'johndoe123');

// fails with arguments
pub("logout");

Package Sidebar

Install

npm i publer

Weekly Downloads

5

Version

2.1.0

License

MIT

Unpacked Size

5.07 kB

Total Files

6

Last publish

Collaborators

  • brielov