Docking

When a dizmo is moved close to another, dizmoViewer asks both of them if they allow docking. If at least one of them answers with true dizmoViewer will display a visual feedback about the docking to the user.

You can allow docking by setting the parameter to true (default is false) in the function dizmo.canDock. However, for a successful docking, both dizmos have to set this parameter to true.

// 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, that is 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. A convention is to use the stdout property for docking.

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

Note: If you have any data which could be used by any other dizmo, write them to your publicStorage! There may be a use-case you have not thought of yet, but other developers will!

You have two possibilities to exchange data between docked dizmos. The first is to exchange data once "by contact", that is when the dizmos are docked or one dragged onto another, and the second is a constant exchange.

Exchange data once

We illustrate how to exchange data when the 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 (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);
});