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

1.0.2 • Public • Published

pubs2

Minimalistic context and action based PubSub.

A quick code exercise about a random idea to subscribe to notifications related to an object and its actions without extending the event emitter.

It's like a reducer but for any object instance, not just for state management.

Cheers! 🍻

Install

npm install pubs2

Usage

import pubs from 'pubs2';

type Actions = "update";
const s = pubs<object, Actions, any>();

const anObject: object = {};

const onupdate = s.subscribe([anObject, "update"],
  (object: object, action: Actions, payload: any) => {
    // execute code ...
  });

// publish something
s.publish([anObject, "update"], "payload can be anything");

// unsubscribe
s.unsubscribe([anObject, "update"], onupdate));

// or if you remove the "observed" object
s.unsubscribe([anObject]);

Readme

Keywords

Package Sidebar

Install

npm i pubs2

Weekly Downloads

2

Version

1.0.2

License

MIT

Unpacked Size

11.7 kB

Total Files

14

Last publish

Collaborators

  • benqus