Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

events-broadcast

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

events-broadcast

broadcast events

  • 1.0.3
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

events-broadcast leverages events to broadcast singly, in combination, or to all selected events.

Installation

npm i events-broadcast

Usage

var eb = require("events-broadcast"),

Test

* to test local functionality: npm run local_test
* mocha test: npm test

Example local_test

"use strict"

/*
* @author Jim Manton: jrman@risebroadband.net
* @since 2019-04-24
* test application
*/

var colors = require('colors'),
    log4js = require("log4js"),
    log4js_tagline = require("log4js-tagline"),
    events_broadcast = require('./app.js'),
    tagline,
    logger,
    append,
    lne


log4js.configure({
    appenders: { myLog: { type: 'file', filename: 'my.log' } },
    categories: { default: { appenders: ['myLog'], level: 'debug' } }
})

tagline = new log4js_tagline(log4js, {
    "display": ["trace", "debug", "info", "warn", "error", "fatal", "mark"],
    "output": {
        "to_local_file": true,
        "to_datadog": true
    }
})
logger = log4js.getLogger('myLog')

append = tagline.appender('line')
lne = new append(tagline).setConfig({ "format": "lne(@name(): @file:@line:@column)" })

logger.debug('start of test').tag(lne).tagline()

var eb = new events_broadcast()
    .set({ "group": { "name": "group-1", "events": [{ "event": "refresh", "id": 1 }, { "event": "two", "id": 2 }] } })
    .set({ "group": { "name": "group-2", "events": [{ "event": "one", "id": 1 }, { "event": "two", "id": 2 }, { "event": "refresh", "id": 3 }] } })
    .set({ "group": { "name": "group-3", "events": [{ "event": "refresh", "id": 1 }] } })
    .error(function (errorArray) {
        errorArray.forEach(function (item) {
            logger.error(item).tag(lne).tagline()
        })
    }).success(function (data) {
        logger.info(data).tag(lne).tagline()
    })
    .on({ "groups": "all", "events": "all" }, function (data) {
        var d = JSON.stringify(data)
        logger.info(d).tag(lne).tagline()
    })
    /*
    .on({ "groups": "all", "events": "refresh" }, function (data) {
        var d = JSON.stringify(data)
        logger.info(d).tag(lne).tagline()
    })
    .on({ "groups": "all", "events": "one" }, function (data) {
        var d = JSON.stringify(data)
        logger.info(d).tag(lne).tagline()
    })
    .on({ "groups": "all", "events": "two" }, function (data) {
        var d = JSON.stringify(data)
        logger.info(d).tag(lne).tagline()
    })
    .on({ "groups": "group-2", "events": "one" }, function (data) {
        var d = JSON.stringify(data)
        logger.info(d).tag(lne).tagline()
    })
    .on({ "groups": "group-2", "events": "refresh" }, function (data) {
        var d = JSON.stringify(data)
        logger.info(d).tag(lne).tagline()
    })
    .on({ "groups": "group-1", "events": "refresh" }, function (data) {
        var d = JSON.stringify(data)
        logger.info(d).tag(lne).tagline()
    })

    .on({ "groups": "all", "events": "all" }, function (data) {
        var d = JSON.stringify(data)
        logger.info(d).tag(lne).tagline()
    })
   .on({ "groups": ["group-1", "group-2"], "events": ["one", "refresh"] }, function (data) {
        var d = "This is ONE, REFRESH processing(" + JSON.stringify(data) + ")"
        logger.info(d).tag(lne).tagline()
    })
    */
    .do({ "groups": "all", "emit": ["refresh"] })
    //.do({ "groups": "all", "emit": "all" })
    //.do({ "groups": ["group-1", "group-2"], "emit": ["one", "refresh"] })
    .do({ "groups": "all", "emit": ["one", "two"] })
    //.do({ "groups": "["group-1", "group-2"]", "emit": ["one", "refresh"] })
    .do({ "groups": ["group-2"], "emit": ["two"] })
    .done()

Example events-broadcast output

[debug] myLog - (msg: start of test) lne((): events-broadcast/test.js:36:8) [info] myLog - (msg: {"name":"group-1","event":{"event":"refresh","id":1}}) lne(callback(): events-broadcast/test.js:51:16) [info] myLog - (msg: {"name":"group-2","event":{"event":"refresh","id":3}}) lne(callback(): events-broadcast/test.js:51:16) [info] myLog - (msg: {"name":"group-3","event":{"event":"refresh","id":1}}) lne(callback(): events-broadcast/test.js:51:16) [info] myLog - (msg: {"name":"group-1","event":{"event":"two","id":2}}) lne(callback(): events-broadcast/test.js:51:16) [info] myLog - (msg: {"name":"group-2","event":{"event":"one","id":1}}) lne(callback(): events-broadcast/test.js:51:16) [info] myLog - (msg: {"name":"group-2","event":{"event":"two","id":2}}) lne(callback(): events-broadcast/test.js:51:16) [info] myLog - (msg: {"name":"group-2","event":{"event":"two","id":2}}) lne(callback(): events-broadcast/test.js:51:16) [info] myLog - (msg: success done) lne(success_callback(): events-broadcast/test.js:47:16)

Keywords

FAQs

Package last updated on 10 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc