2.1.0 • Published 11 months ago

publer v2.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

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");
2.1.0

11 months ago

2.0.1

11 months ago

2.0.0

11 months ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

3 years ago

0.0.1

3 years ago

0.0.0

3 years ago