-
Notifications
You must be signed in to change notification settings - Fork 7
Closed
Labels
Description
A few ideas that are work in progress for potential datx-jsonapi-react lib:
HOC component ideas
injectApi
Alternative names:
- injectAsync
- injectData
- injectAPI
- query
- queryAPI
- fetch
Usage:
@inject('state')
@injectApi({
albums: Album, // Load the first page
tags: { model: Tag, options: { loadAll: true } }, // Load all tags
photos: { model: Photo, reqOptions: { filter: { album: 123 } } }, // With custom request options
})
@observer
class MyComponent extends React.Component<{
state: MyJsonapiCollection;
albums: IJsonapiView;
tags: IJsonapiView;
photos: IJsonapiView;
loading: {
albums: boolean;
tags: boolean;
photos: boolean;
};
}> {
// ...
}infinite
Usage (combination with injectApi):
@inject('state')
@injectApi({
albums: Album, // Load the first page
tags: { model: Tag, options: { loadAll: true } }, // Load all tags
photos: { model: Photo, reqOptions: { filter: { album: 123 } } }, // With custom request options
})
@infinite('photos', 200) // Load more photos, with a 200px threshold when scrolling
@observer
class MyComponent extends React.Component<{
state: MyJsonapiCollection;
albums: IJsonapiView;
tags: IJsonapiView;
photos: IJsonapiView;
loading: {
albums: boolean;
tags: boolean;
photos: boolean;
};
loadMore(): void; // Load more data manually if needed
}> {
// ...
}paginated (TBD)
- exposes a response object with pageInfo and a
onPageChangemethod for loading more data.
Prerequisites
datx-jsonapiversion 0.16 or newer- defined
config.pageInfoParser - defined
config.getPaginationParams