webMethods Business Console Documentation 10.5 | webMethods Business Console Documentation | Developing Gadgets for Business Console | Communicating Between Gadgets | Communicating Between Gadgets Using Events | Using EventBus
 
Using EventBus
The gadget framework provides an AngularJS service called as EventBus to allow communication between gadgets. The EventBus can effectively provide gadget communication using publish-subscribe mechanism.
To use EventBus in your gadgets:
1. Inject the EventBus provider in the controller if not already included.
gadget_controller.$inject = [ '$scope', 'RestServiceProvider','EventBus',
'$log','config'];
//INJECTING EVENTBUS IN CONTROLLER
2. Add the listener logic to the subscriber controller(s). In the defineListener block, invoke addEventListener on the eventBus with the event type name.
this.eventBus.addEventListener("SOME_EVENT_NAME",this.
_handleEvents.bind(this));
3. Provide the logic for handling the event in the _handeEvents block as shown below. Here, the exampleHandleEventAction function is invoked after receiving the event. Define the exampleHandleEventAction function on $scope inside the defineScope block.
_handleEvents:function(eventType,payload,context){
/* Logic to handle events
*/
switch(eventType){
case "SOME_EVENT_NAME":
/* Add Event Handling Logic for GLOBAL_EVENT */
this.$scope.exampleHandleEventAction(payload);
//ONCE EVENT IS RECEIVED, INVOKE THE exampleHandleEventAction
function on $scope.
break;
}
},
4. Clean up the listener on Controller unload. This is required to eliminate unnecessary event calls when no controller is available on the view.
this.eventBus.removeEventListener("SOME_EVENT_NAME",this.
_handleEvents.bind(this));
5. Trigger the event from the publisher controller.
this.eventBus.fireEvent("SOME_EVENT_NAME", "Some Event!");

Copyright © 2014-2019 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.