Options
All
  • Public
  • Public/Protected
  • All
Menu

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 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
     }
} 

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:

let branch = ['|~drive~|--|~filePicker~|---=A|~computer~|--...--=B|~fileSaver~|']

let modules = instantiateModules({...}) 

let adaptors    = {
    A : ({data,context}) => ({
            data, //<- data is forwarded
            // the filename is saved for latter
            context: { originalFile: data.file.name},
        }),
    B : ({data,context}) => ({
            data, //<- data is forwarded 
            // we recover and use the saved variable
            configuration: { 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.

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 .

( {data, configuration, context}, helpers) => {...}

The helpers available for a module and their description should have been made available by the developer of the flux-pack.

Hierarchy

  • Adaptor

Index

Constructors

Properties

Methods

Constructors

constructor

  • new Adaptor(adaptorId: string, mappingFunction: string | ((Message: any, helpers: {}) => Message<unknown>)): Adaptor
  • Parameters

    • adaptorId: string

      unique id of the adaptor

    • mappingFunction: string | ((Message: any, helpers: {}) => Message<unknown>)

      the mapping function, either the string content of the mappingFunction or directly the mapping function

    Returns Adaptor

Properties

Readonly adaptorId

adaptorId: string

Private Readonly asString

asString: string

Readonly mappingFunction

mappingFunction: (Message: any, helpers: {}) => Message<unknown>

Type declaration

    • (Message: any, helpers: {}): Message<unknown>
    • Parameters

      • Message: any
      • helpers: {}
        • [key: string]: any

      Returns Message<unknown>

Methods

toString

  • toString(): string

Generated using TypeDoc