Class
The DataSourceManager is used to manage data source, including create/get/destroy data source instance.
Please always use DataSourceManager.getInstance() to use this class. For example, to get a data source, you can use DataSourceManager.getInstance().getDataSource(dsId) .
For widget developer, DataSourceManager.getInstance() return the same instance for both widget and widget's settings.
To use data source, the recommended way is to use DataSourceComponent , which is more handy.
Methods
| Method | Returns | Notes |
|---|---|---|
createAllDataSources() | Promise<DataSource[]> | Return the successfully created data sources only. For the failed created data sources, return null. |
createAllDataSourcesByTime(num, ms) | Promise<void> | Create all data sources by time. By default, the method will start to create 30 data sources (do not wait for them to be created), then wait for 1000 ms, and then start to create the next 30 data sources. When creating one data source, the method won't create any of its child data sources. |
createDataSource(mainDataSourceId, dataViewId?, localId?, createError?) | Promise<DataSource> | This method is used to create data source instance. Main data source, data view or local data source are created as data source instance. |
createDataSourceByUseDataSource(useDs, localId?, batchInstanceStatusChange?) | Promise<DataSource> | Create data source according to the used data source info, and will create a local data source if localId is passed in. |
getDataSource(dsId) | DataSource | Return the data source instance by ID. If the data source is not created, it will return undefined. |
getInstance() | DataSourceManager | Return the instance of DataSourceManager. If the instance is not created, it will create a new one. If the instance is created, it will return the existing one. The instance is shared by the app and the builder. |
createAllDataSources
Class MethodcreateAllDataSources(): Promise<DataSource[]>Return the successfully created data sources only. For the failed created data sources, return null.
Returns
Promise<DataSource[]>createAllDataSourcesByTime
Class MethodcreateAllDataSourcesByTime(num: number, ms: number): Promise<void>Create all data sources by time. By default, the method will start to create 30 data sources (do not wait for them to be created), then wait for 1000 ms, and then start to create the next 30 data sources. When creating one data source, the method won't create any of its child data sources.
When creating data sources by time, the method will batch to dispatch the data source instance status changes ( NotCreated and Created ) by passing batchInstanceStatusChange to true.
It is to reduce the number of dispatches and improve the performance.
If widgets create data sources by the data source component (via createDataSourceByUseDataSource method), the batchInstanceStatusChange will be set as false by default.
That is to say, won't batch to dispatch the data source instance status changes if the data sources are used by widgets.
Parameters
| Parameter | Type | Default |
|---|---|---|
num | number | 30 |
ms | number | 1000 |
Returns
Promise<void>createDataSource
Class MethodcreateDataSource(mainDataSourceId: string, dataViewId?: string, localId?: string, createError?: boolean): Promise<DataSource>This method is used to create data source instance. Main data source, data view or local data source are created as data source instance.
The parameter can be a data source id, data source config JSON or DataSourceConstructorOptions .
If pass in dataViewId , this method will create a data view.
If pass in dataViewId and localId , this method will create a local data view.
If pass in localId , this method will create a local data source.
If pass in createError , this method will dispatch the data source instanceStatus as CreateError .
To create a main data source instance, this method do the followings:
- Create the data source object.
- Call the object's
ready()method. - Call the object's
fetchSchema()method.
When start to create the data source instance, this method will set the data source instanceStatus as NotCreated at first.
The instanceStatus will be set as Created when the creation process is done. The instanceStatus will be set as CreateError if an error occurs.
Parameters
| Parameter | Type |
|---|---|
main | string |
data | string |
local | string |
create | boolean |
Returns
Promise<DataSource>createDataSource(dsJson: IMDataSourceJson, dataViewId?: string, localId?: string, createError?: boolean): Promise<DataSource>This method is used to create data source instance. Main data source, data view or local data source are created as data source instance.
The parameter can be a data source id, data source config JSON or DataSourceConstructorOptions .
If pass in dataViewId , this method will create a data view.
If pass in dataViewId and localId , this method will create a local data view.
If pass in localId , this method will create a local data source.
If pass in createError , this method will dispatch the data source instanceStatus as CreateError .
To create a main data source instance, this method do the followings:
- Create the data source object.
- Call the object's
ready()method. - Call the object's
fetchSchema()method.
When start to create the data source instance, this method will set the data source instanceStatus as NotCreated at first.
The instanceStatus will be set as Created when the creation process is done. The instanceStatus will be set as CreateError if an error occurs.
Parameters
| Parameter | Type |
|---|---|
ds | IMDataSourceJson |
data | string |
local | string |
create | boolean |
Returns
Promise<DataSource>createDataSource(options: DataSourceConstructorOptions): Promise<DataSource>This method is used to create data source instance. Main data source, data view or local data source are created as data source instance.
The parameter can be a data source id, data source config JSON or DataSourceConstructorOptions .
If pass in dataViewId , this method will create a data view.
If pass in dataViewId and localId , this method will create a local data view.
If pass in localId , this method will create a local data source.
If pass in createError , this method will dispatch the data source instanceStatus as CreateError .
To create a main data source instance, this method do the followings:
- Create the data source object.
- Call the object's
ready()method. - Call the object's
fetchSchema()method.
When start to create the data source instance, this method will set the data source instanceStatus as NotCreated at first.
The instanceStatus will be set as Created when the creation process is done. The instanceStatus will be set as CreateError if an error occurs.
Parameters
| Parameter | Type |
|---|---|
options | DataSourceConstructorOptions |
Returns
Promise<DataSource>createDataSourceByUseDataSource
Class MethodcreateDataSourceByUseDataSource(useDs: UseDataSource | IMUseDataSource, localId?: string, batchInstanceStatusChange?: boolean): Promise<DataSource>Create data source according to the used data source info, and will create a local data source if localId is passed in.
Parameters
| Parameter | Type |
|---|---|
use | UseDataSource | IMUseDataSource |
local | string |
batch | boolean |
Returns
Promise<DataSource>getDataSource
Class MethodgetDataSource(dsId: string): DataSourceReturn the data source instance by ID. If the data source is not created, it will return undefined.
Parameters
| Parameter | Type |
|---|---|
ds | string |
Returns
DataSourcegetInstance
getInstance(): DataSourceManagerReturn the instance of DataSourceManager. If the instance is not created, it will create a new one. If the instance is created, it will return the existing one. The instance is shared by the app and the builder.
Returns
DataSourceManager