Skip to content
This repository was archived by the owner on May 27, 2022. It is now read-only.

Commit fffa8f8

Browse files
authored
Merge pull request #58 from data-provider/release
Release 1.2.0
2 parents c55218a + dff9be2 commit fffa8f8

File tree

20 files changed

+1454
-937
lines changed

20 files changed

+1454
-937
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
### Fixed
1111
### Removed
1212

13+
## [1.2.0] - 2020-06-21
14+
15+
### Added
16+
- feat(polling): Add usePolling hook and withPolling HOC
17+
18+
### Changed
19+
- chore(deps): Update dependencies
20+
1321
## [1.1.0] - 2020-06-14
1422

1523
### Added

README.md

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,25 @@
1414
npm i --save @data-provider/react
1515
```
1616

17+
## Available hooks
18+
19+
* [useDataProvider](#usedataproviderprovider-equalityfn)
20+
* [useData](#usedataprovider-equalityfn)
21+
* [useLoading](#useloadingprovider)
22+
* [useLoaded](#useloadedprovider)
23+
* [useError](#useerrorprovider)
24+
* [usePolling](#usepollingprovider-interval)
25+
26+
## Available HOCs
27+
28+
* [withDataProvider](#withdataproviderprovider-custompropertiesnamescomponent)
29+
* [withData](#withdataprovider-custompropnamecomponent)
30+
* [withLoading](#withloadingprovider-custompropnamecomponent)
31+
* [withLoaded](#withloadedprovider-custompropnamecomponent)
32+
* [withError](#witherrorprovider-custompropnamecomponent)
33+
* [withPolling](#withpollingprovider-intervalcomponent)
34+
* [withDataProviderBranch](#withdataproviderbranchprovider-custompropertiesnamescomponent-loadingcomponent-errorcomponent)
35+
1736
## Hooks
1837

1938
### `useDataProvider(provider, [equalityFn])`
@@ -143,9 +162,30 @@ const BooksList = () => {
143162
};
144163
```
145164

146-
### `useRefresh(provider)`
165+
### `usePolling(provider, [interval])`
166+
167+
Triggers `cleanDependenciesCache` method of the provider each `interval` miliseconds while the component is "alive". It can be used in multiple components at the same time for the same provider. In that case, the used interval will be the lower one, and it will be recalculated each time a component is added or removed.
168+
169+
This hook can also be used with [Data Provider selectors][data-provider-selectors], as it will clean the cache of all selector dependencies. So, if you are using a selector combining data from two axios providers, for example, it will result in repeating both provider http requests and recalculating the selector result every defined interval.
170+
171+
#### Arguments
172+
173+
* `provider` _(Object)_: [Data Provider][data-provider] provider or selector instance.
174+
* `interval` _(Object)_: Interval in miliseconds to clean the provider dependencies cache. Default is 5000.
147175

148-
Triggers `read` method of the `provider` first time the component is rendered, and each time its cache is cleaned. This hook is used internally by the other ones, but you could also use it separatelly.
176+
#### Example
177+
178+
```jsx
179+
import { useData, usePolling } from "@data-provider/react";
180+
181+
import { books } from "../data/books";
182+
183+
const BooksList = () => {
184+
const data = useData(books);
185+
usePolling(books, 3000);
186+
// Do your stuff here. Books will fetched again from server every 3 seconds
187+
};
188+
```
149189

150190
## HOCs
151191

@@ -328,9 +368,28 @@ const BooksList = ({ booksError }) => {
328368
export default withError(books, "booksError")(BooksList);
329369
```
330370

331-
### `withRefresh(provider)(Component)`
371+
### `withPolling(provider, [interval])(Component)`
372+
373+
This High Order Component works as the hook `usePolling` described above.
374+
375+
#### Arguments
376+
377+
* `provider` _(Object)_: [Data Provider][data-provider] provider or selector instance, or a function as described in the [withDataProvider HOC docs](#withdataproviderprovider-custompropertiesnamescomponent)
378+
* `interval` _(Object)_: Interval in miliseconds to clean the provider dependencies cache. Default is 5000.
379+
380+
#### Example
332381

333-
This High Order Component triggers the `read` method of the provider each time the provider cache is cleaned. It is used internally by the rest of HOCs, but you could also use it separately.
382+
```jsx
383+
import { withData, withPolling } from "@data-provider/react";
384+
385+
import { books } from "../data/books";
386+
387+
const BooksList = ({ data }) => {
388+
// Do your stuff here. Books data will fetched again from server every 3 seconds
389+
};
390+
391+
export default withPolling(books, 3000)(withData(books)(BooksList));
392+
```
334393

335394
#### Arguments
336395

@@ -366,6 +425,7 @@ Contributors are welcome.
366425
Please read the [contributing guidelines](.github/CONTRIBUTING.md) and [code of conduct](.github/CODE_OF_CONDUCT.md).
367426

368427
[data-provider]: https://www.data-provider.org
428+
[data-provider-selectors]: https://www.data-provider.org/docs/api-selector
369429
[axios]: https://github.com/axios/axios
370430
[get-started]: https://www.data-provider.org/docs/getting-started
371431
[basic-tutorial]: https://www.data-provider.org/docs/basics-intro

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module.exports = {
2929

3030
// The glob patterns Jest uses to detect test files
3131
testMatch: ["**/test/**/?(*.)+(spec|test).js?(x)"],
32+
// testMatch: ["**/test/withPolling.spec.js"],
3233

3334
transform: {
3435
".js$": "babel-jest",

0 commit comments

Comments
 (0)