Handler embeddedHandler Type RUIHandler {onConstructionFunction=start} feedback TextLabel; function start() InfoBus.subscribe("com.mycompany.sample.test", showPublish); end function showPublish(eventName STRING in, data ANY in) feedback.text = "The " + eventName + " event occurred and passed " + data; end end
In a more realistic case, the showPublish function might receive a record with several fields and then transmit the data to a remote service.
For example, the following handler embeds the previous one, publishes the event, and causes display of the following statement: The sample.text event occurred and passed input data for a service:
Handler InfoBusTest Type RUIHandler { initialUI = [myButton, myDiv] } myButton Button{text = "Publish the event", onClick ::= clickHandler}; myDiv Div { children = [new embeddedHandler{}.feedback] }; function clickHandler(e Event in) InfoBus.publish("com.mycompany.sample.test", "input data for a service"); end end
Note that the function InfoBus.publish does not include the name of the showPublish function. Instead, the Infobus acts as a mediator, ensuring that the appropriate function is invoked.
InfoBusCallback(eventName String in, data any in)
Infobus.subscribe also returns a subscription value (type ANY), which you can use to unsubscribe from the event.
If a Rich UI handler subscribes to the Infobus, that handler cannot be removed from memory. For example, if the user’s button click creates a handler in a function, and if the handler subscribes to the Infobus, the handler and its widgets cannot be removed from memory until the handler unsubscribes from the Infobus.
In most cases, memory is freed by the EGL runtime code. However, the following topic describes a case in which you are in greater control of memory management: “Rich UI memory management for Microsoft™ Internet Explorer.”
An event name is composed of one or more tokens—character symbols such as sample and test (in our example). each of which is separated from the next by a dot.
InfoBus.publish("com.mycompany.update.sales.new.employee", "some data"); InfoBus.publish("com.mycompany.update.marketing.new.employee", "some data"); InfoBus.publish("com.mycompany.update.outreach.new.employee", "some data");
InfoBus.publish("com.mycompany.update.sales.new.employee", "some data"); InfoBus.publish("com.mycompany.update.sales.temporary.employee", "some data"); InfoBus.publish("com.mycompany.update.sales.outreach.new.temporary.employee", "some data");
Rich UI does not support the specification phrases related to filter or scope.