Giter VIP home page Giter VIP logo

mitt-emitter's Introduction

mitt-emitter

This is a redesigned package to add the concept of topics like RabbitMQ. You can now use the special characters "*" and "#" to get a topic.

The original package you can find at: https://github.com/developit/mitt - © [Jason Miller]

Table of Contents

Install

This project uses node and npm. Go check them out if you don't have them locally installed.

$ npm install --save mitt-emitter

Then with a module bundler like rollup or webpack, use as you would anything else:

// using ES6 modules
import MittEmitter from 'mitt-emitter'

// using CommonJS modules
var MittEmitter = require('mitt-emitter')

The UMD build is also available on unpkg:

<script src="https://unpkg.com/mitt-emitter/dist/mitt-emitter.umd.js"></script>

Usage

import MittEmitter from 'mitt-emitter'

const emitter = new MittEmitter();

// listen to an event
emitter.on('foo', e => console.log('foo', e) )

// listen topic event
emitter.on('organization.*.device.1', (type, e) => console.log(type, e) )
emitter.emit('organization.1.device.1', { a: 'b' })

// listen topic event
emitter.on('organization.*.device.*', (type, e) => console.log(type, e) )
emitter.emit('organization.2.device.2', { a: 'b' })

// listen topic event
emitter.on('organization.*.device.#', (type, e) => console.log(type, e) )
emitter.emit('organization.1.device.1.apple.linux', { a: 'b' })

// listen topic event
emitter.on('organization.#', (type, e) => console.log(type, e) )
emitter.emit('organization.1.device.1.apple.linux', { a: 'b' })

// working with handler references:
function onFoo() {}
emitter.on('foo', onFoo)   // listen
emitter.off('foo', onFoo)  // unlisten

License

MIT License © Thiago Anselmo

mitt-emitter's People

Contributors

thiagoanselmo avatar

Stargazers

 avatar Martin avatar

Watchers

 avatar

Forkers

toniktoo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.