0.0.2 • Published 8 years ago

typed-topics v0.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

Typed Topic is a module for pub-sub with runtime type checking. The runtime type checking can be accomplished with Joi schemas or a user provided library and matching schemas.

        const schema = Joi.object().keys({
            category: Joi.string().alphanum().min(1).required(),
            action: Joi.string().alphanum().min(1).required()
        });

        const topic = new TypedTopic({ type: 'analyticsEvents', schema, validator: Joi });

        topic.subscribe(event => console.log(event));

        // prints event + some metadata
        topic.log({ category: 'buy-button', action: 'click' });

        // throws error due to schema violation
        topic.log({ category: 12 });

        // cancels all subscriptions (additional calls to topic.log() have no effect)
        topic.close();

Getting Started

The Typed Topic module can be loaded as:

  • A CommonJS / Node module available at npmjs
  • A script tag (creates the global variable typedTopic)

Examples

Coming soon, see the spec file for now.

Contributors