Docking

This page covers data exchange through docking in the dizmoViewer. In the dizmo software, applications integrate by moving dizmos close to one another (docking). You have two possibilities to exchange data between docked dizmos. The first is to exchange data once, and the second is a constant exchange.

Enable docking

When dizmos are docked, dizmoViewer asks them if they allow docking. dizmoViewer displays visual feedback if at least one of them answers true. For successful docking, both dizmos have to set this parameter to true.

You can allow docking by setting the function parameter in dizmo.canDock to true. The default is false.

// disable docking
dizmo.canDock(false);

// enable docking
dizmo.canDock(true);

The function dizmo.onDock will notify you when another dizmo tries to dock to yours.

dizmo.onDock(function(dockingDizmo) {
    console.log('Docked to dizmo with id ' + dockingDizmo.identifier);
});

The function dizmo.onUnDock will notify you when an already docked dizmo undocks (disconnects).

dizmo.onUndock(function(dockingDizmo) {
    console.log('Undocked from dizmo with id ' + dockingDizmo.identifier);
});

Make data available for the docked dizmo

Docked dizmos can read and write to any property in the public part of the docked dizmos' storage. It is best practice to use the stdout property for docking.

dizmo.publicStorage.setProperty('stdout', 'hello docked dizmo!');
dizmo.publicStorage.getProperty('stdout');

If you have data that you want all other dizmos to be able to use, write them to your publicStorage.

Exchange data once

How is data exchanged when docking occurs? First, we need to be notified about a dizmo docking to ours. Then, we grab the stdout value from the docked dizmo:

dizmo.onDock(function(dockingDizmo) {
    var stdout = dockingDizmo.publicStorage.getProperty('stdout');
    // do something with the stdout variable
});

Constant data exchange

To constantly monitor data, use the subscribeTo function. You may also or subscribeToRecursive for grouped data:

var subscriptionId;

dizmo.onDock(function(dockingDizmo){
    subscriptionId = dockingDizmo.publicStorage.subscribeToProperty('stdout', handleDataChange);
});

function handleDataChange(path, val, oldVal) {
    var stdout = val;
    // do something with the stdout variable
}

Remember to cancel the subscription once the dizmos are undocked. To cancel the subscription made above, you would use

dizmo.onUndock(function(undockedDizmo) {
    dizmo.publicStorage.unsubscribeProperty(subscriptionId);
});