# ts-pubsy

> Fully Typed PubSub Mechanism with Channel and Payload autocompletion.

Latest version **0.3.0** (published 2022-12-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install ts-pubsy
pnpm add ts-pubsy
yarn add ts-pubsy
bun add ts-pubsy
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2022-12-29 |
| First published | 2022-12-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 8.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Gabriel C. Troia |
| Maintainers | gabrielctroia |
| Keywords | pubsub, typed, messaging, observer |

## Links

- npm: https://www.npmjs.com/package/ts-pubsy
- Repository: https://github.com/movesthatmatter/ts-pubsy
- Homepage: https://github.com/movesthatmatter/ts-pubsy#readme
- Issues: https://github.com/movesthatmatter/ts-pubsy/issues
- npm.io page: https://npm.io/package/ts-pubsy

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^2.4.1

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 0.3.0 (latest) — 2022-12-29
- 0.2.0 — 2022-12-29
- 0.1.1 — 2022-12-29
- 0.1.0 — 2022-12-29

## README

# ts-pubsy

Fully Typed PubSub Mechanism with Channel and Payload autocompletion.

# Usage

```
import { Pubsy } from 'ts-pubsy';

type Game = {
  id: string;
  players: [User[id], User[id]];
  winner?: User[id];
}

type GameEvents = {
  onNewGame: Game;
  onGameFinish: { id: string, winner: User[id] };
}

const gamePubsy = new Pubsy<GameEvents>();

// Subscriptions

gamePubsy.subscribe('onNewGame', (game) => {
  // do stuff with the Game object
});

gamePubsy.subscribe('onGameFinished', (game) => {
  console.log(game.winner);
});


// Publish (later on)

gamePubsy.publish('onNewGame', {
  id: '1',
  players: ['player-1', 'player-2'],
  winner: undefined,
});

gamePubsy.publish('onGameFinish', {
  id: '1',
  winner: 'player-2',
});

```

---
_Source: https://npm.io/package/ts-pubsy · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
