require("babel/polyfill");
import {Module} from '../Module.js';
import {default as PubSub} from 'pubsub-js';
import {events} from './DataSourcesEvents.js';
require("babel/polyfill");
import {Module} from '../Module.js';
import {default as PubSub} from 'pubsub-js';
import {events} from './DataSourcesEvents.js';
depends: Kronicle.Module, Kronicle.DataSourcesEvents, pubsub-js This class is used to load Kronicle Datasources. The object is then passed along to the core to allow access to DataSources The constructor takes one argument:
export class DataSources extends Module {
constructor(sources = []){
this.name = "DataSources";
this.sources = { };
PubSub.publish(events.BeforeDataSourcesLoaded);
for(let source of sources) {
this.sources[source.name] = source;
PubSub.publish(events.DataSourceLoaded, source);
}
PubSub.publish(events.AfterDataSourcesLoaded);
return this;
}
This method is a hook into the BeforeDataSourcesLoaded event. It takes one argument:
beforeDataSourcesLoaded(cb) {
PubSub.subscribe(events.BeforeDataSourcesLoaded, cb);
}
This method is a hook into the DataSourceLoaded event. Triggered after each DataSource is loaded. It takes one argument:
dataSourceLoaded(cb){
PubSub.subscribe(events.DataSourceLoaded, cb);
}
This method is a hook into the AfterDataSourcesLoaded event. Triggered after all DataSource are loaded. It takes one argument:
afterDataSourcesLoaded(cb){
PubSub.subscribe(events.AfterDataSourcesLoaded, cb);
}
This method is used to add a DataSource to the sources. It takes one argument:
addDataSource(source){
this.sources[source.name] = source;
}
This method is used to remove a DataSource from the sources. It takes one argument:
removeDataSource(name){
this.sources[name] = null;
}
}