5.0.1 • Published 21 days ago

@zthun/helpful-query v5.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
21 days ago

Helpful Query

Helpful query provides helper classes that solve the problem of trying to create components with reusable functionality such as filtering, sorting, searching and pagination.

The Source Pattern

At the heart of this package is what we call, the source pattern. In most designs, we often tell components WHAT the data is. We query a rest endpoint, we receive a page of data, and we send that data to the component to display back to the end user.

When done in this manner, specific features, such as filtering, sorting, searching, and pagination must be implemented over and over again, as the actual implementation of that set of data depends on the rest service being called. Many 3rd party libraries that attempt to support this out of box will support said features, but they are almost always client side restricted, meaning that you must pull down the entire data set instead of just a single page.

The source pattern solves this problem by telling components HOW to get the data instead of WHAT the data is. This simple change in thinking allows us to construct components that handle the pagination, sorting, filtering, and searching operations for us, and the only responsibility of the caller is to explain to the component where and how to retrieve the data.

Data Request and Source

The root of the source pattern lies with two specific contracts - the request object and the source implementation. The request object will be provided by the component being implemented, and the source implementation describes how to retrieve the specific page of data.

Here is an example of the implementation. The actual implementations provided by this library are more robust, but these will illustrate the idea.

export interface IZDataRequest {
  page: number;
  size: number;
  search: string;
  sort: Array<{ subject: string; direction: 1 | 0 }>;
}

export interface IZDataSource<T> {
  count(): Promise<number>;
  retrieve(request: IZDataRequest): Promise<T[]>;
}

A component would take as input an object that implements an IZDataSource<T> contract, and will pass a request to it when it is ready to display the data. It will need to include it's own loading state, how to paginate, and what features it will give the user to sort, filter, and search.

5.0.1

21 days ago

5.0.0

1 month ago

4.1.1

1 month ago

4.1.0

1 month ago

4.0.4

1 month ago

4.0.3

1 month ago

4.0.2

1 month ago

4.0.1

2 months ago

4.0.0

2 months ago

3.16.1

2 months ago

3.16.0

2 months ago

3.15.0

2 months ago

3.12.0

2 months ago

3.12.2

2 months ago

3.11.0

2 months ago

3.13.0

2 months ago

3.11.1

2 months ago

3.10.0

3 months ago

3.9.0

3 months ago

3.8.0

3 months ago

3.6.0

3 months ago

3.4.0

3 months ago

3.5.0

3 months ago

3.3.1

3 months ago

3.3.0

3 months ago

3.2.0

4 months ago

0.21.0

9 months ago

0.20.1

10 months ago

0.20.0

10 months ago

2.3.0

8 months ago

2.2.1

9 months ago

0.19.0

10 months ago

2.2.0

9 months ago

2.4.0

6 months ago

2.1.0

9 months ago

2.0.0

9 months ago

0.18.0

10 months ago

0.17.1

10 months ago

3.0.0

6 months ago

0.21.6

9 months ago

0.21.5

9 months ago

0.21.4

9 months ago

0.21.3

9 months ago

0.21.2

9 months ago

0.21.1

9 months ago

0.11.0

11 months ago

0.12.0

11 months ago

0.11.1

11 months ago

0.13.0

11 months ago

0.14.0

11 months ago

0.15.0

11 months ago

0.14.1

11 months ago

0.16.0

11 months ago

0.15.1

11 months ago

0.14.2

11 months ago

0.17.0

11 months ago

0.16.1

11 months ago

0.16.2

11 months ago

0.10.0

11 months ago

0.9.0

12 months ago

0.8.1

1 year ago

0.8.0

1 year ago

0.8.2

1 year ago

0.7.0

1 year ago

0.6.0

1 year ago

0.5.0

1 year ago

0.4.1

1 year ago

0.4.0

1 year ago

0.3.0

1 year ago

0.2.0

1 year ago