@tipcity/localsocket

Event emitters for everyone

Usage no npm install needed!

<script type="module">
  import tipcityLocalsocket from 'https://cdn.skypack.dev/@tipcity/localsocket';
</script>

README

LocalSocket ci npm downloads javascript style guide

Event Emitters for everybody

install

npm install @tipcity/localsocket `or` yarn add @tipcity/localsocket

usage

localsocket.on(connected, [callback])

Listen and react to events within a sandbox. When a listener is registered, it is queued up in an array of suspended rections. Once an event is received, all the registered callbacks are invoked in order.

It is also possible to pass a sequence of events in order. If the events are received in that order, the registerd callback is invoked.

arguments
  • tasks - An array or object containing functions to run. Each function is passed a callback(err, result) which it must call on completion with an error err (which can be null) and an optional result value.
  • callback(err, results) - An optional callback to run once all the functions have completed. This function gets a results array (or object) containing all the result arguments passed to the task callbacks.
example
var LocalSocket = require('@tipcity/localsocket')

localSocket = new LocalSocket("test");

localSocket.connect(); // manually connect to localsocket
localSocket.disconnect(); // manually disconnect from localsocket
localSocket.on('foo', () => {}); // trigger alawys, returns an eventKey
localSocket.once('bar', () => {}); // trigger only once 
localSocket.on(['foo bar baz'], () => {}); // when the three events are dispatched in this order, will ignore other events in between
localSocket.onOrderOf(['foo bar baz'], () => {}); // called always when the three events must have happened sequentially without a break
localSocket.onceOrderOf(['foo bar baz'], () => {}); // called only once when the three events must have happened sequentially without a break
localSocket.remove(eventKey); // remove a single listener from the register
localSocket.drop(); // drop the localsocket instance


localSocket.limitConnections(value); // set a max listener for this event. Throws an error, if a new listener is registered passed the limit
localSocket.setEventMaxListener(eventKey, value); // set a max listener for this event. Throws an error, if a new listener is registered passed the limit


Works in all javascript environment

license

MIT. Copyright (c) Tipcity.