Communication between controls

There are many possible ways to communicate between controls. This is not an exhaustive list.

  1. Directly between control instances
  2. Between control instances through the CustomControlModule
  3. Through a PageModule
  4. Session Storage

1. Directly between control instances

For a custom control, Page#getControlByName returns a CustomControl interface which is the public interface supported by all custom controls (the blue box in the diagram).

To obtain a reference to the instance created from your module (the dark gray box in the diagram), use the CustomControl#instance property.

const oModuleInstance = await oControlHost.page.getControlByName( "Control1" ).instance;
// The module instance is available here so you can call your own methods.
oModuleInstance.methodDefinedInYourModule();

Since the modules remain loaded for the lifetime of the report, variables defined at the module scope are accessible by all instances of the control.

define( function() {
"use strict";
let variableSharedBetweenInstances = null;
...

Similar to #2. The page module (which can be added to all pages) can be accessed by all custom controls to share state, even across pages since the page module also remains loaded for the lifetime of the report.

const oModuleInstance = await oControlHost.page.pageModuleInstance;
// The module instance is available here

4. Session Storage

Browsers support sessionStorage which can be used to store and share state between controls.