-
Notifications
You must be signed in to change notification settings - Fork 0
Loader
Kevin Warne edited this page Sep 8, 2015
·
23 revisions
The Loader is used to load and cache multiple data files from multiple sources asynchronously. It uses the d3 Convenience Methods to load and parse external files of various types. After all files have completed their load process the callback function will be executed.
var loader = d2b.UTILS.loader();
var files = [
{key: 'people', path: 'http://path-to-file.example', file: 'people.csv'},
{key: 'dates', path: 'http://path-to-file.example', file: 'dates.json'}
];
loader(files, function(data){
console.log('Done with first load!');
console.log(data.people);
console.log(data.dates);
});
files.push({key: 'states', path: 'http://path-to-file.example', file: 'dates.topo.json'});
loader(files, function(data){
console.log('Done with second load!');
console.log(data.people);
console.log(data.dates);
console.log(data.states);
});# d2b.UTILS.loader()
Returns a constructor for a new loader.
A files array may be passed to specify information about the content that is being loaded. Each file can contain several options:
- "file" - the name of the file including the extension
- "key" - the key will be used to access this particular data set from the returned data
- defaults to the file name
- "path" - the path to fetch the file
- defaults to the d2b CDN
- "type" - the type of the file (e.g. json, csv, xml..)
- defaults to the file extension
If a file fails to load, null will be returned for that file.
If successive loads are done, files will be cached into memory (by their "key") for future use.