Transforming the data is common when the output of a source module is not exactly
what expect the destination module. It can be for instance that the source module
emit a data of type {value: number} while the destination is expecting a straight number.
In this case the adaptor would be:
// The incoming message is provided as argument, // the function returns the outgoing message, // the one interpreted by the destination module ({data, context}) => {return {data:data.value,context:context// discuss a bit latter }}
Transforming the configuration is used to provide to the destination module
a dynamic configuration.
This use case of adaptor is described in details here.
The context part of a message is called user-context.
It vehicles information that the builder of a Flux app wants to be broadcasted along the
data flow of the application.
It is used as an append-only dictionary of values, and gets transferred from modules to modules
automatically (to some extends).
An example of a use case: in an application a file (whatever it is)
is loaded from a drive, some computations are done from it, maybe some user interactions,
and at latter point in the data flow an updated content need to be saved on the same original file.
The schematic code:
letbranch = ['|~drive~|--|~filePicker~|---=A|~computer~|--...--=B|~fileSaver~|']letmodules = instantiateModules({...}) letadaptors = {A : ({data,context}) => ({data, //<- data is forwarded// the filename is saved for lattercontext: { originalFile:data.file.name}, }),B : ({data,context}) => ({data, //<- data is forwarded // we recover and use the saved variableconfiguration: { filename:context.originalFile }, })}
In the adaptor A the information data.file.name is available, it is saved in the context.
Latter on, in adaptor B this information is reused to provide the configuration.filename to the module
fileSaver.
The modules can provide helpers (functions, data or whatever)
that relates to their processing and may be useful to expose to the consumer.
Adaptors take as second argument the helpers (if any) provided by the associated module,
the full signature of an adaptor is .
Adaptor
An adaptor transforms an incoming message reaching a module just before it gets injected in the input's onTriggered callback.
It maps a Message to a Message and can act on any of the data, configuration or context parts.
Data part: adjusting module intercommunication 🗣
Transforming the data is common when the output of a source module is not exactly what expect the destination module. It can be for instance that the source module emit a data of type
{value: number}
while the destination is expecting a straightnumber
. In this case the adaptor would be:Configuration part: let's enable dynamic configuration 🤘
Transforming the configuration is used to provide to the destination module a dynamic configuration. This use case of adaptor is described in details here.
Context part: long distance communication ∿
The context part of a message is called user-context. It vehicles information that the builder of a Flux app wants to be broadcasted along the data flow of the application. It is used as an append-only dictionary of values, and gets transferred from modules to modules automatically (to some extends).
An example of a use case: in an application a file (whatever it is) is loaded from a drive, some computations are done from it, maybe some user interactions, and at latter point in the data flow an updated content need to be saved on the same original file.
The schematic code:
In the adaptor A the information data.file.name is available, it is saved in the context. Latter on, in adaptor B this information is reused to provide the configuration.filename to the module fileSaver.
Helpers
The modules can provide helpers (functions, data or whatever) that relates to their processing and may be useful to expose to the consumer. Adaptors take as second argument the helpers (if any) provided by the associated module, the full signature of an adaptor is .
The helpers available for a module and their description should have been made available by the developer of the flux-pack.