Module

@psionic/emit

A framework for emitting and receiving custom events.

View Source emit/src/index.js, line 1

Methods

# static emit(eventName, dataopt)

Emits the given event for all listeners to respond to with some optional additional data provided.

Parameters:
Name Type Attributes Default Description
eventName string

The name of the event to emit

data Object | * <optional>
{}

The additional data to emit with the event; this will be passed as the only param to each listener's callback function

View Source emit/src/emit/emit.js, line 26

Examples
// Emit a "saved" event with no additional data added
emit('saved');
// Emit a "saved" event with profile data attached
emit('saved', { name: 'John' });

# static onEmit(eventName, callback) → {EmitListener}

Creates a new listener for a given event.

Parameters:
Name Type Description
eventName string

The name of the event to create the listener for

callback function

The function to call whenever the given event is emitted; this function should take in the additional data object as its only param

View Source emit/src/receive/receive.js, line 39

The object to interface with the created listener

EmitListener
Example
// Create a listener for when the "saved" event is fired
const savedListener = onEmit('saved', () => console.log('Saved!'));

// In order to cancel it, call the returned object's `cancel` method
savedListener.cancel();

Type Definitions

Object

# EmitListener

An object for interfacing with a create listener.

Properties:
Name Type Description
cancel function

The function to call to cancel the given listener

View Source emit/src/receive/receive.js, line 9