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

1.0.4 • Public • Published

purin-pubsub

Only 1KB, TypeScript-friendly Publish/Subscribe library.

Tips: Purin just Pudding

Where to get

npm i purin-pubsub

How to use

import { definePurinPubsub } from "purin-pubsub";

type YourData = {
  count: number;
};

const purin = definePurinPubsub<YourData>();

const unsubcribe = purin.subscribe("count", ({ key, value }) => {
  console.log(key, value); // echo: count 1

  // unsubscribe is also very simple! execute it, this function will not be executed
  unsubcribe();
});

purin.publish("count", 1);

// or you can arbitrarily retrieve the value of the last published value
console.log(purin.pull("count")); // echo: 1

Package Sidebar

Install

npm i purin-pubsub

Weekly Downloads

0

Version

1.0.4

License

none

Unpacked Size

5.83 kB

Total Files

8

Last publish

Collaborators

  • akirarika