New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

eso

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eso

Event; Status; Observe :: A pubsub for window events.

latest
Source
npmnpm
Version
0.1.3
Version published
Maintainers
1
Created
Source

#eso ###Events Subscriber with Status Control

version 0.1.3
A Common JS Module, that I really should publish onto NPM. The point of this "pubsub emitter", is to sit at a top level of an app instance, ie: app.emitter, and allow you to create app States and Events, and use them together, or at least as a place to keep an organised record of your window events with their relative functions associated.

The Module itself works by returning an API as on require self executes and instantiates new instances of the Status and Listener Objects. They both share data via their private Scope Object, used internally.

##API methods Status By keeping States, callbacks can be made throughout the app when the status changes, as well as limiting the execution of Events.

params denoted with *asterix mean they are not required.

  • get(*all:boolean) Passing true returns the current Status, whereas ommitting the param returns all the available states.
  • add(state:string) Will create a new state by the name given.
  • set(state:string) Sets the current status with the name of the state given. Will fail if the state does not exist.
  • on(state:string, callback:function) When the designated state becomes set, the function given will be ran. Ie: callback is run on that state.

Listener Keeping your eventListeners organised, and lets you create and configure these listeners with what will be passed back to the functions you wish to fire, and whether or not they are limited by the app's current status.

  • create(type:string, returns:Object) Create a window event listener, by passing the event type ie: 'mousemove', and what the event will return, based on the original event object.
  • add(type:string, callback:function, *status:string) Adds a method to an existing eventListener, which can also be set to be only fired if the status matches the modules current scope status. The callback function you give it will be passed the event object you established as the returns object you stipulate in the create method.

##Todo's

  • Add remove methods to API.

##Usage Init

var Emitter = require('./eso);

// attach it to your App.
app.emitter = Emitter;

Make a state

app.emitter.status.add('bigbang'); // now state exists to use

// pass your funtion execute when status matches
app.emitter.status.on('bigbang', function() {
	console.log('and so it begins - quicker than you realise.');
})

// change state, and see console log for output.
app.emitter.status.set('bigbang');

Utilise Event Listeners

// build a window level event listener, returning cursor x co-ords
app.emitter.listeners.create('mousemove', { x: e.clientX });

// add a method to the mousemove event
app.emitter.listeners.add('mousemove', function(res){ 
	console.log(res.x); 
}, 'bigbang')

Keywords

eventlistener

FAQs

Package last updated on 16 Aug 2014

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