Intersystem Event Messaging.
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 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)
.
ClosedConnector
is a special connector with no-op send
method.
Request is an event that expects a response from the target connector. Response is an event that is sent to the requesting connector.
Takes original event, prepares it and transfers it to receiving system.
Transfers event to ClosedConnector
on the next tick.
Transfers events via custom provider with postMessage
interface.
InterConnectorOperators links two connectors.
Propagates recieved listed events from one connector to another.