Skip to content

An event publisher implementation that communicates based on type property.

License

Notifications You must be signed in to change notification settings

r7kamura/typed-event-publisher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

typed-event-publisher

An event publisher implementation that communicates based on type property.

Install

npm install typed-event-publisher

Usage

import EventPublisher from 'typed-event-publisher'

const eventPublisher = new EventPublisher();

// Subscribe all events
eventPublisher.subscribe((event) => {
  console.log(event); //=> { bar: 'baz', type: 'foo' }
});

// Subscribe foo events
eventPublisher.on('foo', (event) => {
  console.log(event); //=> { bar: 'baz', type: 'foo' }
});

eventPublisher.publish('foo', { bar: 'baz' });

Import

Import in your favorite style.

// Pattern 1: Using a default export
import EventPublisher from 'typed-event-publisher'

// Pattern 2: Using named exports
import { EventPublisher, Subscription } from 'typed-event-publisher'

// Pattern 3: Using both a default export and named exports
import EventPublisher, { Subscription } from 'typed-event-publisher'

For contributors

# Set up
npm install

# Compile JavaScript files
npm run compile

# Watch changes of JavaScript files
npm run watch

# Run tests
npm run test

About

An event publisher implementation that communicates based on type property.

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published