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

Commit

Permalink
Merge pull request #56 from data-provider/release
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
javierbrea authored Jun 14, 2020
2 parents ae81e02 + 1e393c7 commit c55218a
Show file tree
Hide file tree
Showing 21 changed files with 4,065 additions and 1,038 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed
### Removed

## [1.1.0] - 2020-06-14

### Added
- feat(loaded): Add useLoaded hook and withLoaded HOC
- test(unit): Add unit tests full coverage

### Changed
- chore(deps): Update dependencies
- refactor(useDataProvider): Improve useDataProvider hook performance

### Fixed
- fix(useDataProvider): Removed unused arguments

## [1.0.3] - 2020-05-16

### Changed
Expand Down
60 changes: 59 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Build status][travisci-image]][travisci-url]
[![Build status][travisci-image]][travisci-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Quality Gate][quality-gate-image]][quality-gate-url]

[![NPM dependencies][npm-dependencies-image]][npm-dependencies-url] [![Renovate](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com) [![Last commit][last-commit-image]][last-commit-url] [![Last release][release-image]][release-url]

Expand Down Expand Up @@ -93,6 +93,31 @@ const BooksList = () => {
};
```

### `useLoaded(provider)`

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

#### Arguments

* `provider` _(Object)_: [Data Provider][data-provider] provider or selector instance.

#### Returns

* _(Boolean)_ - Value of the `loaded` property from the provider state.

#### Example

```jsx
import { useLoaded } from "@data-provider/react";

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

const BooksList = () => {
const loaded = useLoaded(books);
// Do your stuff here
};
```

### `useError(provider)`

Triggers `read` and gives you only the `error` property from the state of the provider or selector. When the provider cache is cleaned, it automatically triggers `read` again.
Expand Down Expand Up @@ -237,6 +262,39 @@ const BooksList = ({ booksLoading }) => {
export default withLoading(books, "booksLoading")(BooksList);
```

### `withLoaded(provider, customPropName)(Component)`

This High Order Component triggers the read method of the provider and gives to the component only the `loaded` property from its state.

#### Arguments

* `provider` _(Object)_: [Data Provider][data-provider] provider or selector instance, or a function as described in the [withDataProvider HOC docs](#withdataproviderprovider-custompropertiesnamescomponent)
* `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.

#### Examples

```jsx
import { withLoaded } from "@data-provider/react";

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

const BooksList = ({ loaded }) => {
// Do your stuff here
};

export default withLoaded(books)(BooksList);
```

Using custom property:

```jsx
const BooksList = ({ booksLoaded }) => {
// Do your stuff here
};

export default withLoaded(books, "booksLoaded")(BooksList);
```

### `withError(provider, customPropName)(Component)`

This High Order Component triggers the read method of the provider and gives to the component only the `error` property from its state. It will trigger the `read` method each time the provider cache is cleaned.
Expand Down
4 changes: 2 additions & 2 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
presets: ["@babel/preset-env", "@babel/preset-react"]
};
presets: ["@babel/preset-env", "@babel/preset-react"],
};
14 changes: 7 additions & 7 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ module.exports = {
coverageDirectory: "coverage",

// An object that configures minimum threshold enforcement for coverage results
/* coverageThreshold: {
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100
}
}, */
statements: 100,
},
},

// The test environment that will be used for testing
testEnvironment: "node",
testEnvironment: "jsdom",

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

transform: {
".js$": "babel-jest"
".js$": "babel-jest",
},

setupFiles: ["<rootDir>/jest.init.js"]
setupFiles: ["<rootDir>/jest.init.js"],
};
Loading

0 comments on commit c55218a

Please sign in to comment.