Sub Components
Overview
The Sub Component system enables Components to streamline commonly repeated tasks, incorporate traceability, iterate over arrays or recursive hierarchies, and much more.
Any Orchestration Component may have one or more Sub Components assigned to them, becoming a parent Component. Any Orchestration Component can be used as a parent Component, as a Sub Component, or as both at once. Each parent-to-subcomponent relationship is configured on the parent Component.
Sub Components can be useful for encapsulating generic logic such as calling an API to log, send email, or perform a search operation. By passing a Sub Component an array, a Sub Component can be invoked against each element in that array. Sub Components can have Sub Components of their own, which can be useful for working with hierarchical data structures.
Invoking Sub Components
After the DX Engine invokes a parent Component, it invokes its Sub Components sequentially, and embeds the responses of those Sub Components in the response of that parent Component.
The DX Engine's order of execution is:
- Run the parent Component.
- Cache the raw response (if caching is set).
- Apply the Response Transformation.
- Run any Sub Components, one after another.
- Enrich Context Fields.
Given this, data passed from a parent Component to its Sub Component should reference the contents and configuration of the transformed response. Responses from Sub Components are, therefore, not valid inputs to the Response Transformation on the parent Component.
The Sub Component expects the response of the parent Component to be an object.
Sub Component Inputs and Outputs
The DX Engine creates a unique Context for each Sub Component.
Context Fields and Sub Components
If a Sub Component accesses a Context Field, then the DX Engine:
- Checks the context provided by the parent Component.
- Checks the context provided to the parent Component.
- Invokes any Components that enrich that Context Field.
To use Sub Components iteratively, the un-transformed parent Component response must be an array or an array or objects. It will then run for each array element. In most cases, the parent Component should pass all values used by the Sub Component in its unique Context rather than implementing the Sub Component to access Context Fields or other Components directly.
Sub Components cannot enrich a Context Field for use beyond its own execution. However, the parent Component can enrich Context Fields with values added to its response by its Sub Components:
The Sub Component enriches the parent's Response... | ...And the parent Component enriches the Context. |
Sub Components that reference another Component
Sub Components do not register dependencies that the DX Engine resolves automatically. The DX Engine only invokes Components referenced by Sub Components if the Sub Component attempts to access the referenced Component. In this case, the DX Engine passes the unique Context of the Sub Component to the referenced Component.
Passing Component outputs, Context Fields, and Context values to a Sub Component through its parent Component is the ideal data flow pattern. The only recommended exception is where a Sub Component explicitly transforms the response of another Component.
It is preferable if the parent Component passes values from other Components and Context Fields to the Sub Component explicitly as independent Context values in the Sub Component configuration. If the parent Component enriches a Context Field, then the DX Engine can register it as a Context Field provider, rather than the Sub Component (which it cannot "see"). This allows Component families to be activated appropriately to serve a larger query.
Caching with Sub Components
If you cache the parent component, it will only cache the response of parent component before the Sub Component responses are appended to it. The Sub Components will still subsequently execute (unless they themselves are cached).
You can verify which responses are cached by looking for cacheInfo
in the debug response. If both parent and Sub Component are cached, you will see two cacheInfo
objects in the debug object.
Accessing Sub Component Responses
From within the parent Component, or any downstream consumers of the parent, you can access the Sub Component responses in the same way as any other response attribute.
Sub Component responses can also be accessed from other Components. For example, if you wanted to place a condition expression on another Component that depends on the response from a Sub Component, you would access the Sub Component's response through the parent Component's response. For example:
componentResponse('componentParent').data...componentSub.response
Executing Sub Components
When calling DX Engine Webservice APIs that invoke orchestration flows, the DX Engine will invoke Sub Components where applicable. They will not however appear in the Visualizer of the Debugger in the DX Engine UI.
Configuring Sub Components
To configure Sub Components for an Orchestration Component, in the DX Engine UI:
- Edit the Component.
- From the drop-down at the top right, select Sub Components. You may need to scroll this drop-down.
- Add Sub Components. For each Sub Component that you add:
Field | Notes | |
---|---|---|
1 | Property Name | The key under which the response from this Sub Component will appear in the JSON response of the parent component |
1:N | Component Codes | The identifiers of the Sub Components to invoke. The Sub Components referenced must exist in order for the parent Component to save successfully. |
0:N | Context Field:Expression pairs | The Context passed to the Sub Component, using any or all of the parent's response , Context Fields, and JavaScript expressions to provide Context for the Sub Component. |
Related Resources
The following tutorials and recipes contain examples of Sub Components.