Skip to content

Proof of concept React HOC components for datx-jsonapi #94

@DarkoKukovec

Description

@DarkoKukovec

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 onPageChange method for loading more data.

Prerequisites

  • datx-jsonapi version 0.16 or newer
  • defined config.pageInfoParser
  • defined config.getPaginationParams

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions