1.0.0-beta.4 • Published 4 years ago
@thorgate/spa-entities v1.0.0-beta.4
@thorgate/spa-entities
Normalized data storage helper.
Basic Usage
import { createFetchAction, createFetchSaga, createSchemaSelector, createDetailSchemaSelector } from '@thorgate/spa-entities';
import { schema } from 'normalizr';
const article = new schema.Entity('articles');
const fetchAction = createFetchAction('fetch/articles');
// Create worker to fetch data
const fetchSaga = createFetchSaga({
resource: new FetchResource('/articles'),
// method: 'fetch', // This is the default value
key: article.key,
listSchema: [article],
});
const listSelector = createSchemaSelector(article);
const detailSelector = createDetailSchemaSelector(article);
// Usage with `@thorgate/spa-view-manager`
const initialFetchWorker = fetchSaga.asInitialWorker((match) => fetchAction());
function* fetchArticleWatcher() {
yield takeLatest(fetchAction.type, fetchSaga);
}
NormalizedFetchOptions
listSchema
: (schema.Entity[]): Required: List schema to be used for serializationkey
: (string|Function): Required: Field name under which key order is stored underresource
: (Resource|SagaResource): Resource instance used to fetch datamethod
: (ResourceMethods): Resource method usedapiFetchHook
: ((action: FetchActionType) => any | Iterator): Custom fetch method. This can be used to customize response or dispatch additional actions.serializeData
: ((result: any, listSchema: schema.Entity[]) => {result: any, entities: any} | Iterator<Effect | {result: any, entities: any}>): Custom serializer method. This can be used to customize response or dispatch additional actions.timeoutMs
: (number): Timeout after which request is cancelled and error is thrown. Default:3000
createFetchAction
Payload object
method
: (ResourceMethods): Optional override to change<resource>
method used.kwargs
: (Object): Optionally URL kwargs to pass to<resource>.<method>
query
: (Object): Optionally URL Query parameters to pass to<resource>.<method>
data
: (Object): Optionally POST like data to pass to<resource>.<method>
callback
: (Function): Function to call when fetch saga finishes
1.0.0-beta.4
4 years ago
1.0.0-beta.2
4 years ago
1.0.0-beta.0
4 years ago
1.0.0-alpha.40
6 years ago
1.0.0-alpha.39
6 years ago
1.0.0-alpha.37
6 years ago
1.0.0-alpha.36
6 years ago
1.0.0-alpha.35
6 years ago
1.0.0-alpha.34
6 years ago
1.0.0-alpha.33
6 years ago
1.0.0-alpha.32
6 years ago
1.0.0-alpha.31
6 years ago
1.0.0-alpha.30
6 years ago
1.0.0-alpha.29
6 years ago
1.0.0-alpha.28
6 years ago
1.0.0-alpha.27
6 years ago
1.0.0-alpha.24
6 years ago
1.0.0-alpha.23
6 years ago
1.0.0-alpha.22
6 years ago
1.0.0-alpha.20
6 years ago
1.0.0-alpha.19
6 years ago
1.0.0-alpha.18
6 years ago
1.0.0-alpha.17
6 years ago
1.0.0-alpha.16
6 years ago
1.0.0-alpha.15
6 years ago
1.0.0-alpha.14
6 years ago
1.0.0-alpha.12
6 years ago
1.0.0-alpha.11
6 years ago
1.0.0-alpha.8
6 years ago
1.0.0-alpha.7
6 years ago
1.0.0-alpha.6
7 years ago
1.0.0-alpha.5
7 years ago
1.0.0-alpha.4
7 years ago
1.0.0-alpha.3
7 years ago
1.0.0-alpha.2
7 years ago