SDKDOMInstanceBase interface

Addon SDK v1 retirement

The SDKDOMInstanceBase interface is used as the base class for runtime instances that create a DOM element. It derives from SDKWorldInstanceBase.

SDKDOMInstanceBase cannot be directly constructed; it should only be used as a base class.

Methods

PostToDOMElement(handler, data)
PostToDOMElementAsync(handler, data)
Post a message from the runtime instance to the DOM side. The message is received using AddDOMElementMessageHandler() in DOMElementHandler. handler is a string identifying the kind of message. data is a JSON object that is forwarded with the message to provide additional details. The async variant returns a promise that awaits an async handler on the DOM side and forwards the return value back to the runtime, which the returned promise resolves with. The non-async variant simply posts a message and ignores the result (i.e. fire-and-forget).
CreateElement(data)
Instruct the runtime to create a DOM element for this instance. It will end up calling CreateElement() in DOMElementHandler with data (an optional object with additional details to create with). The runtime associates the resulting element with this instance.
FocusElement()
BlurElement()
Helper methods to manage calling focus() and blur() on the instance's associated DOM element.
SetElementCSSStyle(prop, val)
Helper method to set a CSS style on the instance's associated DOM element. For example SetElementCSSStyle("font-family", "sans-serif") will be forwarded to elem.style.fontFamily = "sans-serif" on the DOM side.
GetElementState()
Override to return a JSON object representing the state of the DOM element, e.g. the text content. This is used by CreateElement() and UpdateElementState() to retrieve state to pass to the DOM side.
UpdateElementState()
Send a message from the runtime to the DOM side with the element state (retrieved from GetElementState()). This results in a call to UpdateState(elem, e) on the DOM side. This is a convenient way to make sure any changes to the DOM element are applied.
Addon SDK Manual 2024-05-20