Miss any of our Open RFC calls?Watch the recordings here! »

publisher-subscriber-react-hoc

1.0.2 • Public • Published

About

  • Javascript implementation of publisher subscriber pattern for React (Higher-order-component)
  • Can be used with various event emitters including browser's window object
  • Provides ProviderPublisher and withPublisher

Installation

npm i publisher-subscriber-react-hoc

API

PublisherProvider

interface PublisherProviderProps {
  emitter: Record<string | number | symbol, unknown>;;
  addListenerMethodName: string;
  removeListenerMethodName: string;
};

withPublisher

type EventCallback<P = {}> = (event: P & Event) => void;
 
interface WithPublisherProps {
  eventSubscribersCount(eventName: string): number;
  subscribe(eventName: string, eventCallback: EventCallback): () => void;
  subscribersCount(): number;
  unsubscribeAll(): void;
};

Dependencies

Dependencies

  • publisher-subscriber-pattern@2.0.2
  • react@16.x.x
  • react-dom@16.x.x

DevDependencies

  • Typescript
  • jest, enzyme
  • Babel

Install

npm i publisher-subscriber-react-hoc

DownloadsWeekly Downloads

1

Version

1.0.2

License

ISC

Unpacked Size

19.8 kB

Total Files

27

Last publish

Collaborators

  • avatar