Inter-Widget Communication (IWC)

Data API Action: addChild(nodeKey,nodeValue)

  • nodeKey: String - the name of the Parent API Node. The child node will have its name autogenerated and returned in the resolution. (What is an API Node?)
  • nodeValue: Object - the settings to store the child node.
  • [nodeValue.lifespan]: String - (Optional) the lifespan of the node.

    • "Persistent": will store the node as it changes to the backend. This lifespan is only available to and is the default for the data.api. and is the default lifespan for a data.api node. Changing a node from persistent won't remove it from the backend, rather prevent further updates to be sent to the backend.
    • "Bound": will destroy the node from the bus if it's bound clients (application) are allclosed. Each client that sets a node's lifespan as bound will be added to the resources bound list, once all bound addresses are closed the node is destroyed. This lifespan is default for the names.api.
    • "Ephemeral": will keep the node around as long as the bus is instantiated. When all connections to the bus close this node is destroyed. This lifespan is default for the intents.api and system.api.

      The lifespan parameter does not have to be passed with every set action, rather passing it with the action will toggle changing the lifespan, it is advised to set the lifespan with the initial use of the node in an application.

  • [nodeValue.entity]: Object - (Optional) the value to store in the node.

  • [nodeValue.contentType]: String - (Optional) the content type of the object that will be set. This is an optional parameter, in some APIs nodes have refined control based on the content they hold.

Applies to only the Data API

Creates a Child Node given a A Parent Node's Key

To add a child node, the addChild action is used on the desired parent node.

Adding a child to the Data API triggers its parent to keep an up-to-date list of its child resources in its collection property. This means doing a get on /shoppingCart will return a collection of children node keys.

Since the node key of the child is runtime generated, it will be returned in the promise resolution's entity.resource as a string.

var dataApi = client.data();

var cartEntry = {
    'price': 10,
    'size': 'M',
    'color': 'red',
    'quantity': 1
};

var cartEntryResource = "";

dataApi.addChild('/shoppingCart',{ entity: cartEntry}).then(function(res){
        cartEntryResource = res.entity.resource;
});