Broker

Broker

realizes an object to load one or more data sources

Constructor

new Broker()

Source:
This is the Data.Broker class.
It realizes an object to load one or more data sources and call a user defined function if all sources have been successfully loaded.
It passes an array with the loaded data (Data.Table objects) to the user function
Example
var broker = new Data.Broker()
		.addSource("https://raw.githubusercontent.com/ondata/elezionipolitiche2018/master/dati/scrutiniCI_cm.csv","csv")
		.addSource("https://raw.githubusercontent.com/ondata/elezionipolitiche2018/master/risorse/comuniViminaleISTAT.csv","csv")
		.addSource("https://raw.githubusercontent.com/ondata/elezionipolitiche2018/master/dati/camera_geopolitico_italia.csv","csv")
		.realize(
	function(dataA) {
		var scrutini                    = dataA[0];
		var comuniViminaleISTAT         = dataA[1];
		var camera_geopolitico_italia   = dataA[2];

		scrutini = scrutini.select("WHERE tipo_riga == LI");
		 ...
	});
Returns:
a new Data.Broker object

Methods

addSource(szUrl, szType)

Source:
add one source to the broker
Parameters:
Name Type Description
szUrl String the url of the data source
szType String type of the data (csv,...)
"csv"the source is 'plain text' formatted as Comma Separated Values
delimiter supported: , and ;
"json"the source is JSON (Javascript Object Notation)
"JSON-stat"the source is a JSON object formatted in JSON-stat
"jsonDB"the source is in ixmaps internal data table format
"rss"the source is an xml rss feed
Returns:
the Data.Broker object

error(onError)

Source:
define error function
Example
var broker = new Data.Broker()
     .addSource("https://raw.githubusercontent.com/ondata/elezionipolitiche2018/master/dati/scrutiniCI_cm.csv","csv")

     .error(function(e){alert(e);})

     .realize(
	function(broker) {
         ...
	});
Parameters:
Name Type Description
onError function a user defined function to call when error occurs
Returns:
the Data.Broker object

notify(onError)

Source:
define notify function
Example
var broker = new Data.Broker()
     .addSource("https://raw.githubusercontent.com/ondata/elezionipolitiche2018/master/dati/scrutiniCI_cm.csv","csv")

     .notify(function(e){alert(e);})

     .realize(
	function(broker) {
         ...
	});
Parameters:
Name Type Description
onError function a user defined function to call when notify occurs
Returns:
the Data.Broker object

realize(callback)

Source:
See:
  • Data.Broker.setCallback
start the broker
initiate the process to load the added sources and [optional] define a user function to be called on success.
the argument passed to the user function is an array with the loaded data as "-_anonymous_-Data.Table" objects
Example
...
		.realize(
	function(dataA) {
		var scrutini                    = dataA[0];
		var comuniViminaleISTAT         = dataA[1];
		var camera_geopolitico_italia   = dataA[2];
		...
	});
Parameters:
Name Type Description
callback function type of the data (csv,...)

setCallback(callback)

Source:
Deprecated:
  • use callback in realize()
set the callback function to execute on sucess of all loading.
Note: can also be defined as argument of .realize()
Example
function onSuccess(dataA) {
     ... do something with the loaded data
 }

 var broker = new Data.Broker()
     .addSource("https://raw.githubusercontent.com/ondata/elezionipolitiche2018/master/dati/scrutiniCI_cm.csv","csv")
     .setCallback(onSuccess)
     .realize();
Parameters:
Name Type Description
callback function the callback function
Returns:
the Data.Broker object