Purpose
To describe how to set a hookfunction to a connection using the BDE.
Introduction
Sometimes you will need to process the value of a slot before it propagated through a connection. For example, you may need to do some data transformation to fit the target slots expected structure. To aim that you should use hook function. To declare a hook function, which will be called each time a connection triggers. The hook function will be called with the propagated value and a callback function next, which should be called after the data is processed. A hook function should look as follows:
function (value, next) { // Do your data transformation based on value var newValue = value * 2; // Call next callback with transformed value next(newValue); }
The following sections will show you how to set and use a hook function using the BDE.
An example component
The hook functions are defined for connections between two members. Therefore, we will compose component, we will use the cubx-color-input
and the cubx-textarea
components to get the following compound:
If you are not sure about how to perform compose that component, check the Compose a compound using BDE tutorial.