@virgilioneto/simple-mediator
Simple Mediator
Last updated a year ago by virgilio.missao .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @virgilioneto/simple-mediator 
SYNC missed versions from official npm registry.

Simple Mediator

Build Status codecov

Overview

This is a simple event stream mediator module.

Install

npm install @virgilioneto/simple-mediator

Using

Simple usage

// Load the mediator module
const SimpleMediator = require('@virgilioneto/simple-mediator')
// Get mediator context (use a default context when no context name given)
const defaultContext = SimpleMediator.getContext()

// Bind event on context
defaultContext.on('my-event', data => {
  /* Handle your code here */
})

// Bind once event on context
defaultContext.once('my-event-2', data => {
  /* This event will fire only once */
})

// Emit event to context
defaultContext.emit('my-event', { /* Put your data here */ })

// Emit event to context
defaultContext.emit('my-event-2', { /* Put your data here */ })
// This event will be ignored
defaultContext.emit('my-event-2', { /* Put your data here */ })

Working with multiple contexts

// Load the mediator module
const SimpleMediator = require('@virgilioneto/simple-mediator')
// Get mediator contexts
const context1 = SimpleMediator.getContext('context1')
const context2 = SimpleMediator.getContext('context2')

// Bind event on context1
context1.on('my-event', data => {
  /* Handle your code here */
})
// Bind event on context2
context2.on('my-event', data => {
  /* Handle your code here */
})

// Only context1 will be notified
context1.emit('my-event', { /* Put your data here */ })
// Only context2 will be notified
context2.emit('my-event', { /* Put your data here */ })

Docs

Simple Mediator

Current Tags

  • 1.0.3                                ...           latest (a year ago)

3 Versions

  • 1.0.3                                ...           a year ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (14)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |