The main API classes, Memorelay and MemorelayClient both offer onEvent() methods for registering event listeners. This works, but it's verbose. Here's the skeleton of an example plugin:
function examplePlugin(memorelay: Memorelay) {
memorelay.onEvent(
MemorelayClientCreatedEvent,
({ details: { memorelayClient } }: MemorelayClientCreatedEvent) => {
memorelayClient.onEvent(
IncomingEventMessageEvent,
(incomingEventMessageEvent: IncomingEventMessageEvent) => {
// TODO: Do something with the event.
}
);
}
);
}
Since it's common to listen for MemorelayClientCreatedEvent and IncomingEventMessageEvent, it would be helpful to have method signatures to make this easy. They could be on the objects themselves:
function examplePlugin(memorelay: Memorelay) {
memorelay.onMemorelayClientCreated(({ details: { memorelayClient } }) => {
memorelayClient.onIncomingEventMessage((incomingEventMessageEvent) => {
// TODO: Do something with the event.
});
});
}
Or there could be wrapper functions:
function examplePlugin(memorelay: Memorelay) {
onMemorelayClientCreated(memorelay, ({ details: { memorelayClient } }) => {
onIncomingEeventMessage(memorelayClient, (incomingEventMessageEven) => {
// TODO: Do something with the event.
});
});
}
The former is probably clearer since the API user would be able to use instrumentation to enumerate all the commonly available event types by hitting Ctrl+Tab.
The main API classes,
Memorelay
andMemorelayClient
both offeronEvent()
methods for registering event listeners. This works, but it's verbose. Here's the skeleton of an example plugin:Since it's common to listen for
MemorelayClientCreatedEvent
andIncomingEventMessageEvent
, it would be helpful to have method signatures to make this easy. They could be on the objects themselves:Or there could be wrapper functions:
The former is probably clearer since the API user would be able to use instrumentation to enumerate all the commonly available event types by hitting
Ctrl
+Tab
.