0.35.0 • Published 2 years ago

@osnova/events v0.35.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

@osnova/events

Intersystem Event Messaging.

Concepts

Event

Event is an intention to do something or a signal that something has happened. Event has type and payload fields.

import { makeEventCreator } from '@osnova/events';

const eventRecievedWebsocketMessage = makeEventCreator('RECIEVED_WEBSOCKET_MESSAGE');

const helloMessageEvent = eventRecievedWebsocketMessage({
  message: 'hello',
});

console.log(helloMessageEvent);
/*
{ 
  type: 'RECIEVED_WEBSOCKET_MESSAGE',
  payload: { message: 'Hello' }
}
*/

Connector

Connector is an entity that listens for events, reacts to events and sends events to other connectors.

import { makeEventCreator, ClosedConnector } from '@osnova/events';

const eventRecievedWebsocketMessage = makeEventCreator('RECIEVED_WEBSOCKET_MESSAGE');

const connector = new ClosedConnector();

connector.on('RECIEVED_WEBSOCKET_MESSAGE', (event) => {
  console.log(event); // (1)
});

connector.accept(
  eventRecievedWebsocketMessage({
    message: 'hello',
  })
);

console.log(`The connector has already accepted the event.`); // (2)

/*
  Will print:

  { 
    type: 'RECIEVED_WEBSOCKET_MESSAGE',
    payload: { message: 'Hello' }
  }

  The connector has already accepted the event.

*/

All listeners will be executed synchronously when the connector receives the event via accept. So (1) wil be printed before (2).

Closed connector

ClosedConnector is a special connector with no-op send method.

Request/Response connectors

Request is an event that expects a response from the target connector. Response is an event that is sent to the requesting connector.

EventTransferer

Takes original event, prepares it and transfers it to receiving system.

LocalNextTick Transferer

Transfers event to ClosedConnector on the next tick.

PostMessage Transferer

Transfers events via custom provider with postMessage interface.

InterConnectorOperators

InterConnectorOperators links two connectors.

propagateEvents

Propagates recieved listed events from one connector to another.

0.35.0

2 years ago

0.34.2

2 years ago

0.34.1

2 years ago

0.34.0

2 years ago

0.33.0

2 years ago

0.32.0

3 years ago

0.31.1

3 years ago

0.31.0

3 years ago

0.30.0

3 years ago

0.29.1

3 years ago

0.29.0

3 years ago

0.28.0

3 years ago

0.27.0

3 years ago

0.26.0

3 years ago

0.25.0

3 years ago

0.24.0

3 years ago

0.21.0

3 years ago

0.23.0

3 years ago

0.22.0

3 years ago

0.20.0

3 years ago

0.19.0

3 years ago

0.14.0

3 years ago

0.13.1

3 years ago

0.15.0

3 years ago

0.16.0

3 years ago

0.17.0

3 years ago

0.18.0

3 years ago

0.13.0

3 years ago

0.10.0

3 years ago

0.11.0

3 years ago

0.9.0

3 years ago

0.12.0

3 years ago

0.8.0

3 years ago

0.7.1

3 years ago

0.12.1

3 years ago

0.12.2

3 years ago

0.7.0

3 years ago

0.6.0

3 years ago

0.5.0

3 years ago

0.4.0

3 years ago

0.3.0

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago