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

event-sky

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

event-sky

javascript event pub/sub utility

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
increased by100%
Maintainers
2
Weekly downloads
 
Created
Source

Event Sky (event-sky)

An event pub/sub aggregate utility for javascript apps.

When designing javascript apps it's best to keep modules/features loosely coupled. A great method for accomplishing this is events via publish/subscribe handlers. "Event Sky" was designed to help your apps work without knowing about eachother by utilizing the events with Event Sky.

npm version Build Status semantic-release

JavaScript Style Guide forthebadge forthebadge

forthebadge

An event pub-sub aggregate utility for javascript environments.

Usage

EventSky is bundled as a UMD (universal module design) and can be used in the following ways:

Browser
<script src="https://unpkg.com/event-sky@x.x.x/build.js" />

<script>
  EventSky.on('testEvent', console.info)

  EventSke.trigger('testEvent', 'It works!')

  console.log(EventSky.events)
</script>
Commonjs - Node/Browserify/Webpack

npm i -S event-sky or yarn add event-sky

const EventSky = require('event-sky')

Note: EventSky exports a singleton pattern module. This means it's the same object across require/import's in your commonjs environment, ie:

/* file1.js */

const eventSky = require('event-sky')

eventSky.on('testSingleton', (msg) => console.log(msg))
/* file2.js */

const eventSky = require('event-sky')

eventSky.trigger('testSingleton', 'The singleton pattern works!')

API

Event Hook Lifecycle

You can add event handlers in different lifecycle hooks, beforeAll, on, once, afterAll

const eventSky = require('event-sky')

eventSky.on('newMessage', (data) => { console.log(data) })
eventSky.beforeAll('newMessage'...)
eventSky.afterAll('newMessage'...)
eventSky.once('newMessage'...)

Trigger Events

const data = 'some string...'

eventSky.trigger('newMessage', data)

Turn Handlers Off

// by event id
const eventId = eventSky.on('newMessage', (data) => { console.log(data) })

eventSky.off(eventId)

// or by event name and handler
const handler = (data) => { console.log(data) }

eventSky.on('newMessage', handler)

eventSky.off('newMessage', handler)

A convenience method is available to turn all handlers off associated with an event name, ie:

eventSky.beforeAll('eventName', () => { /* ... */ })

eventSky.on('eventName`, () => { /* ... */ })

// remove all lifecycle hooks for event name "eventName"
eventSky.off.all('eventName')

Firehose

For development purposes you can initialize eventSky to see all event activity in the console:

eventSky.config.firehose = true

Registered Events

You can debug EventSky by checking the registered events and lifecycles via:

console.dir(eventSky.events)

Keywords

FAQs

Package last updated on 08 Jun 2017

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