Store Provider

DataBus is built around redux, and the store provider is responsible for creating redux stores from the data returned from the data storage provider.

The IStoreProvider defines methods for creating stores from resource packs.

Methods

createDatasheetStore

createDatasheetStore(datasheetPack: IServerDatasheetPack, options: IStoreOptions): Promise<Store<IReduxState>> | Store<IReduxState>

Create a redux store from the given datasheet pack.

The implementor is free to extend IStoreOptions and add custom options fields required for the creation of the store.

The implementor actually does not need to create a fresh new store every time, it can return an existing one, for example, in the front end, a global redux store can be returned.

createDashboardStore

createDashboardStore(dashboardPack: IServerDashboardPack, options: IStoreOptions): Promise<Store<IReduxState>> | Store<IReduxState>

Create a redux store from the given dashboard pack.

Example

An example implementation of the store provider for front-end:

interface IClientStoreOptions extends databus.IStoreOptions {
    actionParam: any
}

class ClientStoreProvider implements databus.IStoreProvider {
    createDatasheetStore(dataPack, options: IClientStoreOptions): Promise<Store<IReduxState>> {
        // In front-end, we use the global redux store instead of creating a new one every time.
        globalStore.dispatch(buildSomeAction(dataPack, options.actionParam));
        return globalStore;
    }
    
    createDashboardStore(dashboardPack, options: IClientStoreOptions): Promise<Store<IReduxState>> {
        // similar to above
    }
}

Redux may be abstracted away in the future, and the store provider will become something like an internal representation provider.