Skip to content

Specification, TypeScript interface and type definition that defines the Spec

License

Notifications You must be signed in to change notification settings

pubsub-a/interfaces

Repository files navigation

README

PubSub/A is an interface for libraries implementing the Publish/Subscribe pattern (also often referred to as Observer pattern). The aim of PubSub/A is to provide a unified, asynchronous common API for pubsub (similiar to the Promise/A proposal that defined a unified API for promises).

PubSub/A uses the so-called topic-based Publish/Subscribe with the additional concept of channels for grouping together topics.

A reference implementation written in TypeScript (but usable from plain JavaScript) is available here.

Quick syntax overview

Topic based

const pubsub = new PubSubImplementation();

// channels are initialized asynchronously, provide a way to namespace topics
pubsub.channel('mychannel').then(channel => {

    // subscribe
    channel.subscribe('myTopic', arg => {
        console.log('I received a notification: ' + arg.message);
    })M

    // publish - you can pass any custom object as argument
    channel.publish('myTopic', { message: 'Hello world!' });
});

Specification

The specification is included in the SPECIFICIATION.md file. The interface definitions in this project are written as TypeScript interfaces to provide a statically typed API for better understanding. As this project only includes interfaces and not actual implementations, the resulting output from the TypeScript compiler is an empty JavaScript file.

Implementations

  • pubsub-micro - A reference implementation written in TypeScript but usable from any JavaScript project

Test suite

An official test suite is available to test your implementation for validity.

License

MIT.

About

Specification, TypeScript interface and type definition that defines the Spec

Resources

License

Stars

Watchers

Forks

Packages

No packages published