MultiServiceDataProviderFactory

Some times it's desirable to create a standalone VB type instance programmatically by passing an initial state. In this case, the instance is not backed by a variable, that is, its state is not stored in redux. Instead the instance and/or the caller manages its state essentially. For such cases VB publishes a contract for a TypeFactory that any type author can use. See Custom Extended Types.

The TypeFactory contract is provided in the vb/types/factories/typeFactory.js. VB provides TypeFactory implementations for creating a ServiceDataProvider instance. Refer to the MultiServiceDataProviderFactory for details. (vb/types/factories/multiServiceDataProviderFactory.js)

Methods

createInstance

Returns an instance of the MultiServiceDataProvider. Refer to the JSDocs for the parameters supported on this method. The instance returned supports all methods from the DataProvider contract.

  • options. The object used to instantiate the ServiceDataProvider usually contains these properties:
    • dataProviderOptions. This is its initial or 'default' state.
      • state properties are similar to the properties of a regular MultiServiceDataProvider variable
  • serviceOptions. This optional configuration is needed by the RestHelper to locate the endpoint details.
    • vbContext. This optional configuration is needed by the RestHelpers to locate the service of an endpoint. Typically this object should be obtained from a Visual Builder API or via a callback mechanism.

      If not available, clients should pass in an object with a string property 'extensionId'. The property's value is the id of the extension executing this code (for example, the id of the extension that contains the action chain using the MultiServiceDataProvider).

Here is an example of how a caller can create an instance

Example 1-7 Create SDP

// create SDP
ServiceDataProviderFactory.createInstance({ dataProviderOptions: { endpoint: "foo/getBars", responseType: "barType[]", keyAttributes: "id"} })
  .then((sdpInstance) => {
    // use SDP to create MDP instance
    MultiDataProviderFactory.createInstance({ dataProviderOptions: { dataProviders: { fetchFirst: sdpInstance  } } })
    .then((mdpInstance) => {
      const iter = mdpInstance.fetchFirst();
      iter.next().then((results) => {
        // process results
      });
    });
  });