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

Commit 2695426

Browse files
authored
Merge pull request #104 from data-provider/release
Release v1.4.0
2 parents 26afae6 + c7953cb commit 2695426

31 files changed

+2088
-532
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: check-package-version
2+
on:
3+
pull_request:
4+
branches:
5+
- master
6+
jobs:
7+
check-package-version:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v2
12+
- name: Get NPM version is new
13+
id: check
14+
uses: EndBug/[email protected]
15+
with:
16+
diff-search: true
17+
file-name: ./package.json
18+
file-url: https://unpkg.com/@data-provider/react@latest/package.json
19+
static-checking: localIsNew
20+
- name: Check version is new
21+
if: steps.check.outputs.changed != 'true'
22+
run: |
23+
echo "Version not changed"
24+
exit 1
25+
- name: Get NPM version
26+
id: package-version
27+
uses: martinbeentjes/[email protected]
28+
- name: Check Changelog version
29+
id: changelog_reader
30+
uses: mindsers/[email protected]
31+
with:
32+
version: ${{ steps.package-version.outputs.current-version }}
33+
path: ./CHANGELOG.md
34+
- name: Read version from Sonar config
35+
id: sonar-version
36+
uses: christian-draeger/[email protected]
37+
with:
38+
path: './sonar-project.properties'
39+
property: 'sonar.projectVersion'
40+
- name: Check Sonar version
41+
if: steps.sonar-version.outputs.value != steps.package-version.outputs.current-version
42+
run: |
43+
echo "Version not changed"
44+
exit 1
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: publish-to-github-registry
2+
on:
3+
release:
4+
types: [created]
5+
jobs:
6+
publish:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- run: npm ci
11+
- run: npm run build
12+
# Setup .npmrc file to publish to GitHub Packages
13+
- uses: actions/setup-node@v1
14+
with:
15+
node-version: '12.x'
16+
registry-url: 'https://npm.pkg.github.com'
17+
# Defaults to the user or organization that owns the workflow file
18+
scope: '@data-provider'
19+
- run: npm publish
20+
env:
21+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

CHANGELOG.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,24 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77
## [unreleased]
88
### Added
99
### Changed
10-
### Fixed
10+
### Fixed
1111
### Removed
1212

13+
## [1.4.0] - 2020-11-09
14+
### Added
15+
- feat(hocs): Add withDataLoadedError, withDataLoadingError, withDataLoadingErrorComponents, withDataLoadedErrorComponents
16+
- feat(hooks): Add useDataLoadedError, useDataLoadingError
17+
- chore(ci-cd): Check package version on PRs to master
18+
- chore(release): Publish releases to github packages repository
19+
20+
### Changed
21+
- feat(hocs): Deprecate withDataProvider in favour of withDataLoadingError
22+
- feat(hocs): Deprecate withDataProviderBranch in favour of withDataLoadingErrorComponents
23+
- feat(hooks): Deprecate useDataProvider in favour of useDataLoadingError
24+
25+
### Fixed
26+
- fix(#101): Add hoist-non-react-statics to HOCs
27+
1328
## [1.3.0] - 2020-10-31
1429

1530
### Added

README.md

Lines changed: 108 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ npm i --save @data-provider/react
1616

1717
## Available hooks
1818

19-
* [useDataProvider](#usedataproviderprovider-equalityfn)
19+
* [useDataLoadingError](#usedataloadingerrorprovider-equalityfn)
20+
* [useDataLoadedError](#usedataloadederrorprovider-equalityfn)
2021
* [useData](#usedataprovider-equalityfn)
2122
* [useLoading](#useloadingprovider)
2223
* [useLoaded](#useloadedprovider)
@@ -25,17 +26,19 @@ npm i --save @data-provider/react
2526

2627
## Available HOCs
2728

28-
* [withDataProvider](#withdataproviderprovider-custompropertiesnamescomponent)
29+
* [withDataLoadingError](#withdataloadingerrorprovider-custompropertiesnamescomponent)
30+
* [withDataLoadedError](#withdataloadederrorprovider-custompropertiesnamescomponent)
2931
* [withData](#withdataprovider-custompropnamecomponent)
3032
* [withLoading](#withloadingprovider-custompropnamecomponent)
3133
* [withLoaded](#withloadedprovider-custompropnamecomponent)
3234
* [withError](#witherrorprovider-custompropnamecomponent)
3335
* [withPolling](#withpollingprovider-intervalcomponent)
34-
* [withDataProviderBranch](#withdataproviderbranchprovider-custompropertiesnamescomponent-loadingcomponent-errorcomponent)
36+
* [withDataLoadingErrorComponents](#withdataloadingerrorcomponentsprovider-custompropertiesnamescomponent-loadingcomponent-errorcomponent)
37+
* [withDataLoadedErrorComponents](#withdataloadederrorcomponentsprovider-custompropertiesnamescomponent-notloadedcomponent-errorcomponent)
3538

3639
## Hooks
3740

38-
### `useDataProvider(provider, [equalityFn])`
41+
### `useDataLoadingError(provider, [equalityFn])`
3942

4043
Triggers the provider `read` method and gives you the `data`, `loading` and `error` properties from the state of the provider or selector. When the provider cache is cleaned, it automatically triggers `read` again.
4144

@@ -53,12 +56,37 @@ Use this hook only when you need all mentioned properties, because your componen
5356
#### Example
5457

5558
```jsx
56-
import { useDataProvider } from "@data-provider/react";
59+
import { useDataLoadingError } from "@data-provider/react";
5760

5861
import { books } from "../data/books";
5962

6063
const BooksList = () => {
61-
const [data, loading, error] = useDataProvider(books);
64+
const [data, loading, error] = useDataLoadingError(books);
65+
// Do your stuff here
66+
};
67+
```
68+
69+
### `useDataLoadedError(provider, [equalityFn])`
70+
71+
This hook has the same behavior and interface than the described for the [`useDataLoadingError`](#usedataloadingerrorprovider-equalityfn) one, but it returns the `data`, `loaded` and `error` properties from the state of the provider or selector.
72+
73+
Use this hook only when you don't want to rerender a Component each time the provider is loading. It will return `loaded` as `true` once the provider has loaded for the first time, and it will not change again. This is useful to avoid rerenders in scenarios having "pollings", for example, as it will avoid to render a "loading" each time the data is refreshed.
74+
75+
Take into account that the `loaded` property will not be set as `true` until a success read has finished, so the error may have a value, even when `loaded` is `false`.
76+
77+
#### Returns
78+
79+
* _(Array)_ - Array containing `data`, `loaded` and `error` properties, in that order.
80+
81+
#### Example
82+
83+
```jsx
84+
import { useDataLoadedError } from "@data-provider/react";
85+
86+
import { books } from "../data/books";
87+
88+
const BooksList = () => {
89+
const [data, loaded, error] = useDataLoadedError(books);
6290
// Do your stuff here
6391
};
6492
```
@@ -67,7 +95,7 @@ const BooksList = () => {
6795

6896
Triggers `read` and gives you only the `data` property from the state of the provider or selector. When the provider cache is cleaned, it automatically triggers `read` again.
6997

70-
Arguments are the same than described for the [`useDataProvider` hook](#usedataproviderprovider-equalityfn).
98+
Arguments are the same than described for the [`useDataLoadingError` hook](#usedataloadingerrorprovider-equalityfn).
7199

72100
#### Returns
73101

@@ -189,7 +217,7 @@ const BooksList = () => {
189217

190218
## HOCs
191219

192-
### `withDataProvider(provider, [customPropertiesNames])(Component)`
220+
### `withDataLoadingError(provider, [customPropertiesNames])(Component)`
193221

194222
This High Order Component triggers the read method of the provider and gives to the component the `data`, `loading` and `error` properties from its state. It will trigger the `read` method each time the provider cache is cleaned.
195223

@@ -205,15 +233,15 @@ Use this HOC only when you need all mentioned properties, because your component
205233
Using a provider:
206234

207235
```jsx
208-
import { withDataProvider } from "@data-provider/react";
236+
import { withDataLoadingError } from "@data-provider/react";
209237

210238
import { books } from "../data/books";
211239

212240
const BooksList = ({ data, loading, error }) => {
213241
// Do your stuff here
214242
};
215243

216-
export default withDataProvider(books)(BooksList);
244+
export default withDataLoadingError(books)(BooksList);
217245
```
218246

219247
With custom properties:
@@ -223,7 +251,7 @@ const BooksList = ({ booksData, booksLoading, booksError }) => {
223251
// Do your stuff here
224252
};
225253

226-
export default withDataProvider(books, ["booksData", "booksLoading", "booksError"])(BooksList);
254+
export default withDataLoadingError(books, ["booksData", "booksLoading", "booksError"])(BooksList);
227255
```
228256

229257
Using a function:
@@ -233,7 +261,41 @@ const BookDetail = ({ data, loading, error }) => {
233261
// Do your stuff here
234262
};
235263

236-
export default withDataProvider(({ id }) => books.query({ urlParam: { id }}))(BookDetail);
264+
export default withDataLoadingError(({ id }) => books.query({ urlParam: { id }}))(BookDetail);
265+
```
266+
267+
### `withDataLoadedError(provider, [customPropertiesNames])(Component)`
268+
269+
This hoc has the same behavior and interface than the described for the [`withDataLoadingError`](#withdataloadingerrorprovider-custompropertiesnamescomponent) one, but it provides the `data`, `loaded` and `error` properties from the state.
270+
271+
Use this hook only when you don't want to rerender a Component each time the provider is loading. It will return `loaded` as `true` once the provider has loaded for the first time, and it will not change again. This is useful to avoid rerenders in scenarios having "pollings", for example, as it will avoid to render a "loading" each time the data is refreshed.
272+
273+
Take into account that the `loaded` property will not be set as `true` until a success read has finished, so the error may have a value, even when `loaded` is `false`.
274+
275+
#### Examples
276+
277+
Using a provider:
278+
279+
```jsx
280+
import { withDataLoadedError } from "@data-provider/react";
281+
282+
import { books } from "../data/books";
283+
284+
const BooksList = ({ data, loaded, error }) => {
285+
// Do your stuff here
286+
};
287+
288+
export default withDataLoadedError(books)(BooksList);
289+
```
290+
291+
With custom properties:
292+
293+
```jsx
294+
const BooksList = ({ booksData, booksAreLoaded, booksError }) => {
295+
// Do your stuff here
296+
};
297+
298+
export default withDataLoadedError(books, ["booksData", "booksAreLoaded", "booksError"])(BooksList);
237299
```
238300

239301
### `withData(provider, customPropName)(Component)`
@@ -242,7 +304,7 @@ This High Order Component triggers the read method of the provider and gives to
242304

243305
#### Arguments
244306

245-
* `provider` _(Object)_: [Data Provider][data-provider] provider or selector instance, or a function as described in the [withDataProvider HOC docs](#withdataproviderprovider-custompropertiesnamescomponent)
307+
* `provider` _(Object)_: [Data Provider][data-provider] provider or selector instance, or a function as described in the [withDataLoadingError HOC docs](#withdataloadingerrorprovider-custompropertiesnamescomponent)
246308
* `customPropName` _(String)_: By default, the HOC will pass to the component a `data` property. You can change that prop passing a new property name as second argument.
247309

248310
#### Examples
@@ -275,7 +337,7 @@ This High Order Component triggers the read method of the provider and gives to
275337

276338
#### Arguments
277339

278-
* `provider` _(Object)_: [Data Provider][data-provider] provider or selector instance, or a function as described in the [withDataProvider HOC docs](#withdataproviderprovider-custompropertiesnamescomponent)
340+
* `provider` _(Object)_: [Data Provider][data-provider] provider or selector instance, or a function as described in the [withDataLoadingError HOC docs](#withdataloadingerrorprovider-custompropertiesnamescomponent)
279341
* `customPropName` _(String)_: By default, the HOC will pass to the component a `loading` property. You can change that prop passing a new property name as second argument.
280342

281343
#### Examples
@@ -308,7 +370,7 @@ This High Order Component triggers the read method of the provider and gives to
308370

309371
#### Arguments
310372

311-
* `provider` _(Object)_: [Data Provider][data-provider] provider or selector instance, or a function as described in the [withDataProvider HOC docs](#withdataproviderprovider-custompropertiesnamescomponent)
373+
* `provider` _(Object)_: [Data Provider][data-provider] provider or selector instance, or a function as described in the [withDataLoadingError HOC docs](#withdataloadingerrorprovider-custompropertiesnamescomponent)
312374
* `customPropName` _(String)_: By default, the HOC will pass to the component a `loaded` property. You can change that prop passing a new property name as second argument.
313375

314376
#### Examples
@@ -341,7 +403,7 @@ This High Order Component triggers the read method of the provider and gives to
341403

342404
#### Arguments
343405

344-
* `provider` _(Object)_: [Data Provider][data-provider] provider or selector instance, or a function as described in the [withDataProvider HOC docs](#withdataproviderprovider-custompropertiesnamescomponent)
406+
* `provider` _(Object)_: [Data Provider][data-provider] provider or selector instance, or a function as described in the [withDataLoadingError HOC docs](#withdataloadingerrorprovider-custompropertiesnamescomponent)
345407
* `customPropName` _(String)_: By default, the HOC will pass to the component an `error` property. You can change that prop passing a new property name as second argument.
346408

347409
#### Examples
@@ -374,7 +436,7 @@ This High Order Component works as the hook `usePolling` described above.
374436

375437
#### Arguments
376438

377-
* `provider` _(Object)_: [Data Provider][data-provider] provider or selector instance, or a function as described in the [withDataProvider HOC docs](#withdataproviderprovider-custompropertiesnamescomponent)
439+
* `provider` _(Object)_: [Data Provider][data-provider] provider or selector instance, or a function as described in the [withDataLoadingError HOC docs](#withdataloadingerrorprovider-custompropertiesnamescomponent)
378440
* `interval` _(Object)_: Interval in miliseconds to clean the provider dependencies cache. Default is 5000.
379441

380442
#### Example
@@ -393,14 +455,14 @@ export default withPolling(books, 3000)(withData(books)(BooksList));
393455

394456
#### Arguments
395457

396-
* `provider` _(Object)_: [Data Provider][data-provider] provider or selector instance, or a function as described in the [withDataProvider HOC docs](#withdataproviderprovider-custompropertiesnamescomponent)
458+
* `provider` _(Object)_: [Data Provider][data-provider] provider or selector instance, or a function as described in the [withDataLoadingError HOC docs](#withdataloadingerrorprovider-custompropertiesnamescomponent)
397459

398-
### `withDataProviderBranch(provider, [customPropertiesNames])(Component, LoadingComponent, ErrorComponent)`
460+
### `withDataLoadingErrorComponents(provider, [customPropertiesNames])(Component, LoadingComponent, ErrorComponent)`
399461

400-
This HOC works as the already described [`withDataProvider`](#withdataproviderprovider-custompropertiesnamescomponent), but it will render one component or another depending of the result. If the provider is loading, it will render `LoadingComponent`, if it has an error, it will render `ErrorComponent` (passing the `error` property to it), or `Component` when there is no error and it is not loading (passing the `data` property to it).
462+
This HOC works as the already described [`withDataLoadingError`](#withdataloadingerrorprovider-custompropertiesnamescomponent), but it will render one component or another depending of the result. If the provider is loading, it will render `LoadingComponent`, if it has an error, it will render `ErrorComponent` (passing the `error` property to it), or it will render `Component` when there is no error and it is not loading (passing the `data` property to it).
401463

402464
```jsx
403-
import { withDataProviderBranch } from "@data-provider/react";
465+
import { withDataLoadingErrorComponents } from "@data-provider/react";
404466

405467
import { books } from "../data/books";
406468

@@ -416,7 +478,31 @@ const BooksError = ({ error }) => {
416478
// Do your stuff here
417479
};
418480

419-
export default withDataProviderBranch(books)(BooksList, BooksLoading, BooksError);
481+
export default withDataLoadingErrorComponents(books)(BooksList, BooksLoading, BooksError);
482+
```
483+
484+
### `withDataLoadedErrorComponents(provider, [customPropertiesNames])(Component, NotLoadedComponent, ErrorComponent)`
485+
486+
This HOC works as the already described [`withDataLoadedError`](#withdataloadederrorprovider-custompropertiesnamescomponent), but it will render one component or another depending of the result. If the provider has an error, it will render `ErrorComponent` (passing the `error` property to it), if it has not loaded, it will render `NotLoadedComponent`, or it will render `Component` when there is no error and it has loaded (passing the `data` property to it).
487+
488+
```jsx
489+
import { withDataLoadedErrorComponents } from "@data-provider/react";
490+
491+
import { books } from "../data/books";
492+
493+
const BooksList = ({ data }) => {
494+
// Do your stuff here
495+
};
496+
497+
const BooksNotLoaded = () => {
498+
// Do your stuff here
499+
};
500+
501+
const BooksError = ({ error }) => {
502+
// Do your stuff here
503+
};
504+
505+
export default withDataLoadedErrorComponents(books)(BooksList, BooksNotLoaded, BooksError);
420506
```
421507

422508
## Contributing

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +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"],
32+
// testMatch: ["**/test/hocs.spec.js"],
3333

3434
transform: {
3535
".js$": "babel-jest",

package-lock.json

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)