@mendix/extensions-api - v0.2.4
    Preparing search index...

    Interface IMessagePassingApi

    API for passing messages between different entry points of a component

    interface IMessagePassingApi {
        _apiId: "mendix.MessagePassingApi";
        addEventListener<K extends never>(
            eventType: K,
            listener: EventHandler<{}, K>,
        ): DisposeListener;
        addMessageHandler<TMessageData>(
            onMessage: MessageHandler<TMessageData>,
        ): Promise<HandlerReference>;
        removeEventListener<K extends never>(
            eventType: K,
            listener: EventHandler<{}, K>,
        ): void;
        removeMessageHandler(handlerReference: HandlerReference): Promise<boolean>;
        sendMessage<TMessageData, TResponseData>(
            message: TMessageData,
            onResponse?: ResponseHandler<TResponseData>,
        ): Promise<void>;
        sendResponse<TResponseData>(
            messageId: string,
            response: TResponseData,
        ): Promise<boolean>;
    }

    Hierarchy (View Summary)

    Index

    Properties

    _apiId: "mendix.MessagePassingApi"

    Unique identifier that can be used to register or retrieve a specific API.

    Example: mendix.EditorsAPI, mycompany.MyFunkyAPI

    Methods

    • Adds an event listener for the specified event type.

      Type Parameters

      • K extends never

      Parameters

      • eventType: K

        The type of event to listen for.

      • listener: EventHandler<{}, K>

        The event listener to add.

      Returns DisposeListener

      A function that can be called to remove the event listener.

    • Registers a message handler for messages sent to this entry point. Note that this handler will only receive messages sent from other entry points of the same component, and will never see its own messages. Handler will react only to messages that are sent after the handler is registered.

      Type Parameters

      • TMessageData

      Parameters

      Returns Promise<HandlerReference>

    • Removes an event listener for the specified event type.

      Type Parameters

      • K extends never

      Parameters

      • eventType: K

        The type of event to remove the listener from.

      • listener: EventHandler<{}, K>

        The event listener to remove.

      Returns void

    • Removes a registered message handler. The handler will no longer receive messages and will release any resources it was using.

      Parameters

      • handlerReference: HandlerReference

        The reference to the handler that was returned when the handler was registered.

      Returns Promise<boolean>

      True if the handler was successfully removed, false if no handler with the given reference was found.

    • Broadcasts a message to other entry points that have registered message handlers.

      Type Parameters

      • TMessageData
      • TResponseData

      Parameters

      • message: TMessageData

        Message that will be sent to other entry points, can be any type.

      • OptionalonResponse: ResponseHandler<TResponseData>

        If provided, this function will be called for the first entry point that calls IMessagePassingApi.sendResponse with the messageId of the sent message. Note that this function will be called at most once, so if you are expecting multiple responses, you should register a message handler instead.

      Returns Promise<void>

    • Sends a response to a message. It will invoke the onResponse callback that was passed to the sendMessage method.

      Type Parameters

      • TResponseData

      Parameters

      • messageId: string

        ID of the message to which the response is being sent. ID is obtained from the MessageInfo object in handlers.

      • response: TResponseData

        Response that will be sent back to the sender of the message. Make sure that the type of the response matches the type expected by the onResponse callback.

      Returns Promise<boolean>

      True if the response was successfully sent, false if no message with ID was found or answer was already sent.