diff --git a/.all-contributorsrc b/.all-contributorsrc index 734929b8..efd55eaa 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -231,11 +231,30 @@ "code", "bug" ] + }, + { + "login": "nealeu", + "name": "Neale Upstone", + "avatar_url": "https://avatars1.githubusercontent.com/u/264594?v=4", + "profile": "https://github.com/nealeu", + "contributions": [ + "code" + ] + }, + { + "login": "mbark", + "name": "Martin Barksten", + "avatar_url": "https://avatars1.githubusercontent.com/u/1579384?v=4", + "profile": "https://github.com/mbark", + "contributions": [ + "doc" + ] } ], "contributorsPerLine": 7, "projectName": "react-async", "projectOwner": "async-library", "repoType": "github", - "repoHost": "https://github.com" + "repoHost": "https://github.com", + "skipCi": true } diff --git a/.circleci/config.yml b/.circleci/config.yml index 09c824be..c3da2c0b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -69,7 +69,14 @@ jobs: - checkout - attach_workspace: at: . - - run: yarn test:chromatic + - run: | + if [[ "${CIRCLE_BRANCH}" == renovate/* ]]; then + echo "Skipping Chromatic" + elif [ "${CIRCLE_BRANCH}" == "master" ]; then + yarn test:chromatic --auto-accept-changes + else + yarn test:chromatic + fi workflows: version: 2 diff --git a/.storybook/config.js b/.storybook/config.js index 73808286..a9aa4d72 100644 --- a/.storybook/config.js +++ b/.storybook/config.js @@ -1,6 +1,4 @@ import { configure } from "@storybook/react" -import "storybook-chromatic" - const req = require.context("../stories", true, /\.stories\.js$/) configure(() => req.keys().forEach(filename => req(filename)), module) diff --git a/README.md b/README.md index 0426860a..14982cbb 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,6 @@

React Async
Handle promises with ease. -
-
- - -


@@ -116,42 +111,47 @@ Use it with `fetch`, Axios or other data fetching libraries, even GraphQL. Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)): - + + - - - - - - - + + + + + + + - - - - - - - + + + + + + + - - - - - - - + + + + + + + - - - + + + + +
Gert Hengeveld
Gert Hengeveld

💻 👀 💬
Khartir
Khartir

💻 📦
Lenz Weber
Lenz Weber

💻 📦 🤔
Avinash
Avinash

👀 📖
Fred K. Schott
Fred K. Schott

🔧
Cedric van Putten
Cedric van Putten

💻
Tom Shane
Tom Shane

👀

Gert Hengeveld

💻 👀 💬

Khartir

💻 📦

Lenz Weber

💻 📦 🤔

Avinash

👀 📖

Fred K. Schott

🔧

Cedric van Putten

💻

Tom Shane

👀
Philip Peterson
Philip Peterson

💻
Sibelius Seraphini
Sibelius Seraphini

👀
Jim Cummins
Jim Cummins

👀
Mihkel Sokk
Mihkel Sokk

👀
Jiří Brabec
Jiří Brabec

💻
Andrii U
Andrii U

💡
Matthisk Heimensen
Matthisk Heimensen

💻

Philip Peterson

💻

Sibelius Seraphini

👀

Jim Cummins

👀

Mihkel Sokk

👀

Jiří Brabec

💻

Andrii U

💡

Matthisk Heimensen

💻
Danny Hurlburt
Danny Hurlburt

🤔 📖
Noel Yoo
Noel Yoo

⚠️ 💻 🤔
Adam Ratcliffe
Adam Ratcliffe

💻
Kent C. Dodds
Kent C. Dodds

💻
walter-ind
walter-ind

📖
Jacob Lee
Jacob Lee

💻
Youngrok Kim
Youngrok Kim

💻

Danny Hurlburt

🤔 📖

Noel Yoo

⚠️ 💻 🤔

Adam Ratcliffe

💻

Kent C. Dodds

💻

walter-ind

📖

Jacob Lee

💻

Youngrok Kim

💻
Munir Ahmed Elsangedy
Munir Ahmed Elsangedy

🤔
AlixWang
AlixWang

📖
Sal Olivares
Sal Olivares

💻 🐛

Munir Ahmed Elsangedy

🤔

AlixWang

📖

Sal Olivares

💻 🐛

Neale Upstone

💻

Martin Barksten

📖
+ + This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! diff --git a/docs/getting-started/installation.md b/docs/getting-started/installation.md index 1f87cdcb..bc756dac 100644 --- a/docs/getting-started/installation.md +++ b/docs/getting-started/installation.md @@ -14,3 +14,30 @@ yarn add react-async > This package requires `react` as a peer dependency. Please make sure to install that as well. If you want to use the > `useAsync` hook, you'll need `react@16.8.0` or later. + +## Transpiling for legacy browsers + +This project targets the latest ECMAScript version. Our packages on npm do not contain ES5 code for legacy browsers. If you need to target a browser which does not support the latest version of ECMAScript, you'll have to handle transpilation yourself. Usually this will automatically be handled by the framework you use (CRA, Next.js, Gatsby), but sometimes you may need to tweak your Webpack settings to transpile `react-async` with Babel. + +To transpile `node_modules` with Babel you need to use a `babel.config.js`, for more information see [Babel's documentation](https://babeljs.io/docs/en/configuration#whats-your-use-case). + +In your `webpack.config.js` make sure that the rule for `babel-loader`: + +- doesn't exclude `node_modules` from matching via the `exclude` pattern; +- excludes `core-js` as it shouldn't be transpiled; +- is passed the `configFile` option pointing to the `babel.config.js` file. + +``` +{ + test: /\.(js|jsx)$/, + exclude: /\/node_modules\/core-js\//, + use: [{ + loader: 'babel-loader', + options: { + configFile: './babel.config.js', + // Caching is recommended when transpiling node_modules to speed up consecutive builds + cacheDirectory: true, + } + }] +} +``` diff --git a/examples/basic-fetch/package.json b/examples/basic-fetch/package.json index a2bbd0f3..0704df5e 100644 --- a/examples/basic-fetch/package.json +++ b/examples/basic-fetch/package.json @@ -4,6 +4,7 @@ "private": true, "homepage": "https://react-async.async-library.now.sh/examples/basic-fetch", "scripts": { + "bootstrap": "yarn install", "postinstall": "relative-deps", "prestart": "relative-deps", "prebuild": "relative-deps", @@ -18,7 +19,7 @@ "react-async": "^10.0.0", "react-async-devtools": "^10.0.0", "react-dom": "16.11.0", - "react-scripts": "3.2.0" + "react-scripts": "3.4.1" }, "devDependencies": { "relative-deps": "0.2.0" diff --git a/examples/basic-hook/package.json b/examples/basic-hook/package.json index 9ed10a4e..ac227494 100644 --- a/examples/basic-hook/package.json +++ b/examples/basic-hook/package.json @@ -4,6 +4,7 @@ "private": true, "homepage": "https://react-async.async-library.now.sh/examples/basic-hook", "scripts": { + "bootstrap": "yarn install", "postinstall": "relative-deps", "prestart": "relative-deps", "prebuild": "relative-deps", @@ -18,7 +19,7 @@ "react-async": "^10.0.0", "react-async-devtools": "^10.0.0", "react-dom": "16.11.0", - "react-scripts": "3.2.0" + "react-scripts": "3.4.1" }, "devDependencies": { "relative-deps": "0.2.0" diff --git a/examples/custom-instance/package.json b/examples/custom-instance/package.json index 479c7d39..00304ed3 100644 --- a/examples/custom-instance/package.json +++ b/examples/custom-instance/package.json @@ -4,6 +4,7 @@ "private": true, "homepage": "https://react-async.async-library.now.sh/examples/custom-instance", "scripts": { + "bootstrap": "yarn install", "postinstall": "relative-deps", "prestart": "relative-deps", "prebuild": "relative-deps", @@ -18,7 +19,7 @@ "react-async": "^10.0.0", "react-async-devtools": "^10.0.0", "react-dom": "16.11.0", - "react-scripts": "3.2.0" + "react-scripts": "3.4.1" }, "devDependencies": { "relative-deps": "0.2.0" diff --git a/examples/movie-app/package.json b/examples/movie-app/package.json index 0edb7e9d..949161b7 100644 --- a/examples/movie-app/package.json +++ b/examples/movie-app/package.json @@ -4,6 +4,7 @@ "private": true, "homepage": "https://react-async.async-library.now.sh/examples/movie-app", "scripts": { + "bootstrap": "yarn install", "postinstall": "relative-deps", "prestart": "relative-deps", "prebuild": "relative-deps", @@ -18,7 +19,7 @@ "react-async": "^10.0.0", "react-async-devtools": "^10.0.0", "react-dom": "16.11.0", - "react-scripts": "3.2.0" + "react-scripts": "3.4.1" }, "devDependencies": { "relative-deps": "0.2.0" diff --git a/examples/with-abortcontroller/package.json b/examples/with-abortcontroller/package.json index 8f492537..6ed0d54c 100644 --- a/examples/with-abortcontroller/package.json +++ b/examples/with-abortcontroller/package.json @@ -4,6 +4,7 @@ "private": true, "homepage": "https://react-async.async-library.now.sh/examples/with-abortcontroller", "scripts": { + "bootstrap": "yarn install", "postinstall": "relative-deps", "prestart": "relative-deps", "prebuild": "relative-deps", @@ -18,7 +19,7 @@ "react-async": "^10.0.0", "react-async-devtools": "^10.0.0", "react-dom": "16.11.0", - "react-scripts": "3.2.0" + "react-scripts": "3.4.1" }, "devDependencies": { "relative-deps": "0.2.0" diff --git a/examples/with-graphql/package.json b/examples/with-graphql/package.json index 24869866..9cdbf912 100644 --- a/examples/with-graphql/package.json +++ b/examples/with-graphql/package.json @@ -4,6 +4,7 @@ "private": true, "homepage": "https://react-async.async-library.now.sh/examples/with-graphql", "scripts": { + "bootstrap": "yarn install", "postinstall": "relative-deps", "prestart": "relative-deps", "prebuild": "relative-deps", @@ -19,7 +20,7 @@ "react-async": "^10.0.0", "react-async-devtools": "^10.0.0", "react-dom": "16.11.0", - "react-scripts": "3.2.0" + "react-scripts": "3.4.1" }, "devDependencies": { "relative-deps": "0.2.0" diff --git a/examples/with-nextjs/package.json b/examples/with-nextjs/package.json index bfda792a..9b6479de 100644 --- a/examples/with-nextjs/package.json +++ b/examples/with-nextjs/package.json @@ -4,6 +4,7 @@ "private": true, "main": "index.js", "scripts": { + "bootstrap": "yarn install", "postinstall": "relative-deps", "predev": "relative-deps", "prebuild": "relative-deps", diff --git a/examples/with-react-native/package.json b/examples/with-react-native/package.json index 10a322d8..8edb052b 100644 --- a/examples/with-react-native/package.json +++ b/examples/with-react-native/package.json @@ -4,6 +4,7 @@ "private": true, "main": "node_modules/expo/AppEntry.js", "scripts": { + "bootstrap": "yarn install", "postinstall": "relative-deps", "prestart": "relative-deps", "preandroid": "relative-deps", diff --git a/examples/with-react-router/package.json b/examples/with-react-router/package.json index f2d7ac1b..bb43fd93 100644 --- a/examples/with-react-router/package.json +++ b/examples/with-react-router/package.json @@ -4,6 +4,7 @@ "private": true, "main": "index.js", "scripts": { + "bootstrap": "yarn install", "postinstall": "relative-deps", "prestart": "relative-deps", "prebuild": "relative-deps", diff --git a/examples/with-suspense/package.json b/examples/with-suspense/package.json index a201120f..913ee220 100644 --- a/examples/with-suspense/package.json +++ b/examples/with-suspense/package.json @@ -4,6 +4,7 @@ "private": true, "homepage": "https://react-async.async-library.now.sh/examples/with-suspense", "scripts": { + "bootstrap": "yarn install", "postinstall": "relative-deps", "prestart": "relative-deps", "prebuild": "relative-deps", @@ -18,7 +19,7 @@ "react-async": "^10.0.0", "react-async-devtools": "^10.0.0", "react-dom": "16.11.0", - "react-scripts": "3.2.0" + "react-scripts": "3.4.1" }, "devDependencies": { "relative-deps": "0.2.0" diff --git a/examples/with-typescript/package.json b/examples/with-typescript/package.json index af4b56ce..4115faef 100644 --- a/examples/with-typescript/package.json +++ b/examples/with-typescript/package.json @@ -4,6 +4,7 @@ "private": true, "homepage": "https://react-async.async-library.now.sh/examples/with-typescript", "scripts": { + "bootstrap": "yarn install", "postinstall": "relative-deps", "prestart": "relative-deps", "prebuild": "relative-deps", @@ -21,7 +22,7 @@ "react-async": "^10.0.0", "react-async-devtools": "^10.0.0", "react-dom": "16.11.0", - "react-scripts": "3.2.0", + "react-scripts": "3.4.1", "typescript": "3.7.2" }, "devDependencies": { diff --git a/package.json b/package.json index bce91fd2..e2d06a47 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "packages/*" ], "scripts": { - "bootstrap": "yarn build:packages && yarn workspaces run install", + "bootstrap": "yarn build:packages && yarn workspaces run bootstrap", "clean": "lerna clean", "start": "run-p start:*", "start:examples": "now dev", @@ -36,49 +36,49 @@ "postbump": "yarn build:packages" }, "devDependencies": { - "@babel/core": "7.7.2", - "@babel/plugin-proposal-class-properties": "7.7.0", - "@babel/plugin-proposal-object-rest-spread": "7.6.2", - "@babel/plugin-transform-runtime": "7.6.2", - "@babel/preset-env": "7.7.1", - "@babel/preset-react": "7.7.0", - "@babel/preset-typescript": "7.7.2", + "@babel/core": "7.8.6", + "@babel/plugin-proposal-class-properties": "7.8.3", + "@babel/plugin-proposal-object-rest-spread": "7.8.3", + "@babel/plugin-transform-runtime": "7.8.3", + "@babel/preset-env": "7.8.7", + "@babel/preset-react": "7.8.3", + "@babel/preset-typescript": "7.8.3", "@pika/pack": "0.5.0", - "@pika/plugin-build-node": "0.7.1", - "@pika/plugin-build-types": "0.7.1", - "@pika/plugin-build-umd": "0.7.1", - "@pika/plugin-build-web": "0.7.1", - "@pika/plugin-bundle-types": "0.7.1", - "@pika/plugin-standard-pkg": "0.7.1", - "@pika/plugin-ts-standard-pkg": "0.7.1", - "@storybook/react": "5.2.6", + "@pika/plugin-build-node": "0.9.2", + "@pika/plugin-build-types": "0.9.2", + "@pika/plugin-build-umd": "0.9.2", + "@pika/plugin-build-web": "0.9.2", + "@pika/plugin-bundle-types": "0.9.2", + "@pika/plugin-standard-pkg": "0.9.2", + "@pika/plugin-ts-standard-pkg": "0.9.2", + "@storybook/react": "5.3.14", "@testing-library/jest-dom": "4.2.4", - "@testing-library/react": "9.3.2", - "@typescript-eslint/eslint-plugin": "2.8.0", - "@typescript-eslint/parser": "2.8.0", - "babel-eslint": "10.0.3", + "@testing-library/react": "9.4.1", + "@typescript-eslint/eslint-plugin": "2.22.0", + "@typescript-eslint/parser": "2.22.0", + "babel-eslint": "10.1.0", "babel-jest": "24.9.0", "babel-loader": "8.0.6", - "copyfiles": "2.1.1", - "eslint": "6.6.0", - "eslint-config-prettier": "6.7.0", - "eslint-plugin-jest": "23.0.4", - "eslint-plugin-prettier": "3.1.1", + "copyfiles": "2.2.0", + "eslint": "6.8.0", + "eslint-config-prettier": "6.10.0", + "eslint-plugin-jest": "23.8.1", + "eslint-plugin-prettier": "3.1.2", "eslint-plugin-promise": "4.2.1", - "eslint-plugin-react": "7.16.0", - "eslint-plugin-react-hooks": "2.3.0", + "eslint-plugin-react": "7.18.3", + "eslint-plugin-react-hooks": "2.5.0", "jest": "24.9.0", - "lerna": "3.19.0", + "lerna": "3.20.2", "node-jq": "1.11.0", - "now": "16.6.0", + "now": "16.7.3", "npm-run-all": "4.1.5", "prettier": "1.19.1", "prop-types": "15.7.2", - "react": "16.12.0", + "react": "16.13.0", "react-async": "10.0.0-alpha.0", - "react-dom": "16.12.0", - "storybook-chromatic": "3.1.0", - "typescript": "3.7.2" + "react-dom": "16.13.0", + "storybook-chromatic": "3.5.2", + "typescript": "3.8.3" }, "resolutions": { "@types/react": "16.9.13" diff --git a/packages/react-async-devtools/package.json b/packages/react-async-devtools/package.json index 051c4a28..de29ea57 100644 --- a/packages/react-async-devtools/package.json +++ b/packages/react-async-devtools/package.json @@ -17,6 +17,7 @@ }, "main": "src", "scripts": { + "bootstrap": "yarn install", "build": "pika build", "postbuild": "copyfiles -f ../../LICENSE ../../README.md pkg", "publish": "npm publish pkg" diff --git a/packages/react-async/package.json b/packages/react-async/package.json index 30c51b55..58f73bdb 100644 --- a/packages/react-async/package.json +++ b/packages/react-async/package.json @@ -19,6 +19,7 @@ }, "main": "src", "scripts": { + "bootstrap": "yarn install", "build": "pika build", "postbuild": "copyfiles -f ../../LICENSE ../../README.md pkg", "publish": "npm publish pkg" diff --git a/packages/react-async/src/Async.tsx b/packages/react-async/src/Async.tsx index 340822c6..5d0559e7 100644 --- a/packages/react-async/src/Async.tsx +++ b/packages/react-async/src/Async.tsx @@ -22,23 +22,23 @@ import { ReducerAsyncState, } from "./types" -interface InitialProps { +export interface InitialProps { children?: InitialChildren persist?: boolean } -interface PendingProps { +export interface PendingProps { children?: PendingChildren initial?: boolean } -interface FulfilledProps { +export interface FulfilledProps { children?: FulfilledChildren persist?: boolean } -interface RejectedProps { +export interface RejectedProps { children?: RejectedChildren persist?: boolean } -interface SettledProps { +export interface SettledProps { children?: SettledChildren persist?: boolean } @@ -54,7 +54,7 @@ type GenericAsync = typeof Async & { Settled(props: SettledProps): JSX.Element } -type AsyncConstructor = React.ComponentClass> & { +export type AsyncConstructor = React.ComponentClass> & { Initial: React.FC> Pending: React.FC> Loading: React.FC> diff --git a/packages/react-async/src/index.ts b/packages/react-async/src/index.ts index e35a81b0..1d38c448 100644 --- a/packages/react-async/src/index.ts +++ b/packages/react-async/src/index.ts @@ -1,5 +1,14 @@ import Async from "./Async" -export { default as Async, createInstance } from "./Async" +export { + default as Async, + createInstance, + AsyncConstructor, + FulfilledProps, + InitialProps, + PendingProps, + RejectedProps, + SettledProps, +} from "./Async" export * from "./types" export { default as useAsync, useFetch, FetchOptions, FetchError } from "./useAsync" export default Async