createDataService API
These docs are auto-generated from typings files (
*.d.ts
).
createDataService
Creates the data service to be feed into the <ResiftProvider dataService={dataService} />
or in
Redux middleware.
function createDataService(params: DataServiceParams): any;
DataServiceParams
You must provide an object with the following shape into createDataService
.
See What are data services for more info.
Name | Description | Type | Required |
---|---|---|---|
services | Defines the shape of the data services object you can destructure in the request body of a fetch factory. See here for more info. | { [key: string]: FetchService } | yes |
onError | This callback fires when any promise throw s or catch es with an error from a fetch service.If you're unsure how to handle this error, re-throw: onError: e => { throw e; } | (error: Error) => void | yes |
FetchService
A fetch service is a function that returns data asynchronously. This data is given to ReSift for storage and retrieval.
See What are data services? for more info.
See createHttpService
for a reference implementation of a fetch service.
type FetchService = {
(params: FetchServiceParams): T | Promise;
};
FetchServiceParams
The data service provides fetches services with this object. Fetch services are expected to use these params to implement cancellation correctly.
Name | Description | Type | Required |
---|---|---|---|
onCancel | Adds a callback listener to the cancellation mechanism. If the request is cancelled, the callback given will be invoked. See createHttpService for a reference implementation | (callback: () => void) => void | yes |
getCanceled | Returns whether or not the request has been cancelled. Use this in conjunction with CanceledError to early exit when a cancellation occurs. See createHttpService for a reference implementation | () => boolean | yes |
ServicesFrom
This is a typescript only module. It's used to get the type of the services object. See here for more info.
type ServicesFrom<
ServicesObject extends { [key: string]: (...args: any[]) => any }
> = {
[P in keyof ServicesObject]: ReturnType<ServicesObject[P]>;
};