This project was built starting from typescript-starter repository.
- Cleanup package.json scripts. Right now there are a lot recipes that might never be used.
- Add jest-marble tests
- Fix
npm auditreported issues - Add usage examples
- Send events:
PubSubEvent<T, D = unknown> - Each event has a
typeand payload:data. - The possible event types are generic
PubSubService<T>
- Register by specifying event types
- Subscribers can narrow down the event payload type which is otherwise opaque to the PubSubService
interface EventTypes {
t1: { name: string };
t2: { age: number };
}
type EventIds = keyof EventTypes;
const pubSubService = new PubSubService<EventIds>();
// Publisher
const ev: PubSubEvent<'t1', EventTypes['t1']> = {
type: 't1',
data: { name: 'peanuts' },
};
pubSubService.publish(ev);
// Subscriber
pubSubService.watch(['t1']).subscribe((ev) => {
console.log((ev.data as EventTypes['t1']).name);
});Jest is used for unit testing and coverage, replacing typescript-starter libraries Ava and Nyc.
npm run test:unitruns unit tests and stopsnpm run watch:testruns unit tests in watch modenpm run covrunts unit tets, generates and opens coverage report