ServiceDataProviderFactory

Some times it's desirable to create a standalone VB type instance programmatically by passing an initial state. Here 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 implement. 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 ServiceDataProviderFactory for details. (vb/types/factories/serviceDataProviderFactory.js)

Methods

createInstance

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

  • options, object used to instantiate the ServiceDataProvider with, usually contains these properties
    • dataProviderOptions, its initial or 'default' state.
      • state properties are same as what a regular ServiceDataProvider variable takes
    • serviceOptions, optional configuration needed by the RestHelper to locate the endpoint details. This can be skipped if the dataProviderOptions includes an 'endpoint' property
      • properties:
        • url <string>
        • operationRef <string>

caller can create an instance as follows:

ServiceDataProviderFactory.createInstance({ dataProviderOptions: { endpoint: "foo/getBars", responseType: "barType[]", keyAttributes: "id"} })
  .then((sdpInstance) => {
    const iter = sdpInstance.fetchFirst();
    iter.next().then((results) => {
      // process results
    });
  });