Finsemble: Linking Components

Linking Components


Frequently, users will have components that might want to share or synchronize data. A typical use-case in the finance would be to link several components together so that they share the same stock symbol. Changing the stock symbol in one component would cause the other components to also change their symbol. In this case, we would call the symbol a "linkage".

Components must register themselves as linkable and specify linkage types. This registration and communication between components occurs automatically over the router via FSBL.Clients.LinkerClient. The LinkerClient handles the interfacing with the router so that the component developer can simply focus on passing and receiving linked information.

Links are unique to the group and data type. Linkages are saved in the component's state.

Using The Linker

Item 1 in the image below shows the Linker icon along with a group (yellow) that this component has joined. Groups are added or removed when a user clicks on a group in the Linker Window.

Item 2 shows the Linker Window and a list of colors that represent different Finsemble Linker groups. Currently, if a component joins a group it will receive all messages for that group.

To transmit data to other components, simply call FSBL.Clients.LinkerClient.publish whenever you want to send out an update. This will transmit the given data to all groups that the current component has joined.

    FSBL.Clients.LinkerClient.publish({
        dataType:"symbol",
        data:"AAPL"
    });
    //To send data through the linker.This will send a `symbol` object with the symbol 'AAPL` to
    //any components that is in the same group that is listening for `symbol`

To receive data from other components through the LinkerClient you'll need to subscribe to a specific data type.

    FSBL.Clients.LinkerClient.subscribe("symbol", function(err, data){// Symbol is the data type
        if(err){
            return console.error(err);
        }
        //Do something with data. Data would be AAPL in this case.
    });