Preload Dashboard data

This feature makes the Dashboard data available for the user at load time.

Overview

This consist of a togglable button that, when activated, changes the Widget logic so that the Dashboard data gets preloaded, making it available for the user along with the dashboard loading.

Before this feature was developed, the user could only retrieve data from the Ubidots class by setting an event and capturing the required variable on the callback.

For example, If the user wanted to get his Ubidots Token and the ID of the currently selected device, it could be achieved as follows:

var ubidots = new Ubidots();

ubidots.on('ready', async function () 
{
	token = ubidots.token;	
	deviceID = ubidots.selectedDevice;		
});

However, this requires that the user knows some advanced Javascript knowledge as well as the custom Ubidots events.

With the Preload dashboard data feature, the requirement above can be achieved as easy as:

token = ubidots.token;	
deviceID = ubidots.selectedDevice;

Note that there is no need to instantiate the Ubidots class, since it already has.

By enabling this feature, the readyevent as shown above won't be available anymore to be invoked.

Class' properties when Preload dashboard data is disabled

Upon disabling the preload dashboard data feature, some of the class' properties might appear as undefined this is due to the fact that, the class' instance has not yet fully received the values for its properties. Consider the code snipet below:

const ubidots = new Ubidots();

console.log(ubidots.token);
ubidots.on('receivedToken', function (token) {
    console.log(token);
    console.log(ubidots.token);
})

Albeit ubidots.token is a valid syntax, and indeed the Ubidots class has that property, the first console.log prints undefined however the other two properly print the token, this is because such property is only available after the event has set its value.

Last updated