1.0.0-beta.4 • Published 2 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
2 years ago
1.0.0-beta.2
3 years ago
1.0.0-beta.0
3 years ago
1.0.0-alpha.40
5 years ago
1.0.0-alpha.39
5 years ago
1.0.0-alpha.37
5 years ago
1.0.0-alpha.36
5 years ago
1.0.0-alpha.35
5 years ago
1.0.0-alpha.34
5 years ago
1.0.0-alpha.33
5 years ago
1.0.0-alpha.32
5 years ago
1.0.0-alpha.31
5 years ago
1.0.0-alpha.30
5 years ago
1.0.0-alpha.29
5 years ago
1.0.0-alpha.28
5 years ago
1.0.0-alpha.27
5 years ago
1.0.0-alpha.24
5 years ago
1.0.0-alpha.23
5 years ago
1.0.0-alpha.22
5 years ago
1.0.0-alpha.20
5 years ago
1.0.0-alpha.19
5 years ago
1.0.0-alpha.18
5 years ago
1.0.0-alpha.17
5 years ago
1.0.0-alpha.16
5 years ago
1.0.0-alpha.15
5 years ago
1.0.0-alpha.14
5 years ago
1.0.0-alpha.12
5 years ago
1.0.0-alpha.11
5 years ago
1.0.0-alpha.8
5 years ago
1.0.0-alpha.7
5 years ago
1.0.0-alpha.6
5 years ago
1.0.0-alpha.5
5 years ago
1.0.0-alpha.4
5 years ago
1.0.0-alpha.3
5 years ago
1.0.0-alpha.2
5 years ago