publisher-subscriber-react-hoc
v1.0.2
Published
React Higher-Order Component, which provides 'subscribe', 'unsubscribeAll', 'eventSubscribersCount', 'subscribersCount' methods. Can be used with various eventEmitters, including browser's 'window' object.
Downloads
4
Maintainers
Readme
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
DevDependencies
- Typescript
- jest, enzyme
- Babel