Namespace OWF.RPC
Defined in: Widget.js.
| Constructor Attributes | Constructor Name and Description |
|---|---|
| Method Attributes | Method Name and Description |
|---|---|
| <static> |
OWF.RPC.getWidgetProxy(instanceGuid, callback)
Gets a proxy object that contains methods exposed by other widget.
|
| <static> |
OWF.RPC.handleDirectMessage(fn)
Register a function to be executed when a direct message is received from another widget.
|
| <static> |
OWF.RPC.registerFunctions(objs)
Register one or more functions to OWF to expose to other widgets.
|
Method Detail
<static>
OWF.RPC.getWidgetProxy(instanceGuid, callback)
Gets a proxy object that contains methods exposed by other widget.
OWF.RPC.getWidgetProxy('instanceGuid of widgetA', function(widgetA) {
widgetA.add(1,2,3, function(result) {
console.log(result); // log the result
})
widgetA.sendMessage('some secret message');
});
- Parameters:
- {String} instanceGuid
- instance guid of the widget to import
- {Function} callback
- function that will be executed if the widget is found opened on the current dashboard. The function is passed a proxy object as the first argument which will contain methods that were exposed by the widget. In addition, the proxy abject also has sendMessage method to send a direct message to the widget.
<static>
OWF.RPC.handleDirectMessage(fn)
Register a function to be executed when a direct message is received from another widget.
OWF.RPC.handleDirectMessage(function(msg) {
// do something with the message
});
- Parameters:
- {Function} fn
- function that will be executed when a direct message is received from another widget.
<static>
OWF.RPC.registerFunctions(objs)
Register one or more functions to OWF to expose to other widgets.
Calculator = {
add: function() {
var args = arguments,
val = 0;
for(var i = 0, len = args.length; i < len; i++) {
val += parseFloat(args[i]);
}
return val;
},
multiply: function() {
var args = arguments,
val = 1;
for(var i = 0, len = args.length; i < len; i++) {
val *= parseFloat(args[i]);
}
return val;
}
};
OWF.RPC.registerFunctions([
{
name: 'add'
fn: Calculator.add,
scope: Calculator
},
{
name: 'multiply'
fn: Calculator.multiply,
scope: Calculator
}
]);
- Parameters:
- {Object/Array} objs
- Object or an array of objects of following structure.
{
name: 'name of the function',
fn: function() {},
scope: window //The scope (this reference) in which the function is executed. If omitted, defaults to the browser window.
}