🐙
Docs
  • Welcome to Medusa
  • Hydra
    • Concept
  • MEDUSA
    • Concept
    • Quickstart
    • Expressions
    • Additional functions
    • Inner workings
Powered by GitBook
On this page
  • Run your own logic after message delivery
  • Send your own event from anywhere in the backend code
  • To all users
  • To a specific user
  1. MEDUSA

Additional functions

Run your own logic after message delivery

You can run your own arbitrary JS code before or after the onMessage gets executed.

var _M = _M || {}; //depending on when your script is executed, the _M namespace might exist or not.

_M.preEventHandler = function (incomingMessage) {
    console.log("Gets executed before the event handler gets called at all, so the first moment data comes into your website", incomingMessage);
};

_M.preRender = function (incomingMessage, pendingDomChange) {
    console.log("Gets executed before the render of an incoming DOM Change. The DOM change itself is built and ready to render.", incomingMessage);
};

_M.postRender = function (incomingMessage) {
    console.log("Gets executed after the render of an incoming DOM Change", incomingMessage);
};

Send your own event from anywhere in the backend code

To all users

ActiveSessionRegistry.getInstance().sendToAll( obj );

If you specifically want to send DOMChanges, you'll need to build it:

ActiveSessionRegistry.getInstance().sendToAll(DOMChanges.of("my-field", obj).build());

To a specific user

ActiveSessionRegistry.getInstance().sendToSession(obj, sessionId);

TODO: A cache is used to determine if the last sent message has already been sent to the user. This allows you to call this method in intervals with duplicate events without having to worry about passing duplicate data to the user.

PreviousExpressionsNextInner workings

Last updated 3 years ago