Skip to content

Commit 201f01b

Browse files
authored
[wip] React Async DevTools (closes #43) (#44)
* Setup Storybook. * Cleanup. * Add 'reducer' and 'dispatcher' options to allow external control over internal state. * Essential UI for DevTools. * Re-enable all tests. * Invoke the promiseFn from the dispatcher so we can control its invocation. * Use a global variable to hook up DevTools to each instance of React Async. * Add DevTools.propTypes. * Create a namespace on window. * No need to wrap children. * Styling tweaks. * Fix property access on undefined. * Fix global access to devToolsDispatcher. * Setup Yarn. * wip: Setup subpackages. * Run lint/test/build on preversion instead of prepublish so it will be done before creating a release tag. * Run lint/test/build on preversion instead of prepublish so it will be done before creating a release tag. * Fix monorepo. * Use inline styles instead of a CSS file. * Hoist most scripting and dependencies up to the root. Fixed eslint and jest setup. * Define dependencies in the right place and only once. * Upgrade to @testing-library/react * Bump dependencies. * Use yarn workspaces to bump versions. * We're already at 6.2.2. * Update Travis config. * Make sure we run a clean build before publishing. * Build after bumping, and drop the publish script. * Include publish script just to clarify we should be publishing the pkg dir. * Utility scripts. * Add tests for DevTools and suppress act warnings. * Add lockfile for root package.
1 parent 60cf7a0 commit 201f01b

35 files changed

+12925
-99
lines changed

.babelrc

Lines changed: 0 additions & 11 deletions
This file was deleted.

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
},
1313
"plugins": ["jest", "promise", "react", "react-hooks"],
1414
"rules": {
15-
"react-hooks/rules-of-hooks": "error"
15+
"react-hooks/rules-of-hooks": "error",
16+
"no-console": "error"
1617
},
1718
"settings": {
1819
"react": {

.gitignore

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
pkg/
2-
node_modules/
31
coverage/
4-
package-lock.json
2+
docs/
3+
node_modules/
4+
pkg/
5+
6+
examples/*/yarn.lock

.storybook/config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { configure } from "@storybook/react"
2+
3+
const req = require.context("../stories", true, /\.stories\.js$/)
4+
configure(() => req.keys().forEach(filename => req(filename)), module)

.storybook/webpack.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = async ({ config }) => {
2+
delete config.module.rules[0].include
3+
return config
4+
}

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ language: node_js
22
node_js:
33
- "node"
44
cache:
5+
yarn: true
56
directories:
67
- node_modules
7-
script: npm run lint && npm run test:compat
8+
script: yarn ci
89
after_success:
910
- bash <(curl -s https://codecov.io/bash) -e TRAVIS_NODE_VERSION

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ These can be passed in an object to `useAsync()`, or as props to `<Async>` and c
337337
- `onReject` Callback invoked when Promise rejects.
338338
- `reducer` State reducer to control internal state updates.
339339
- `dispatcher` Action dispatcher to control internal action dispatching.
340+
- `debugLabel` Unique label used in DevTools.
340341

341342
`useFetch` additionally takes these options:
342343

@@ -434,6 +435,13 @@ dispatcher at some point.
434435
> This is a power feature similar to the [state reducer pattern]. It allows you to control state changes by
435436
> intercepting actions before they are dispatched, to dispatch additional actions, possibly later in time.
436437
438+
#### `debugLabel`
439+
440+
> `string`
441+
442+
A unique label to describe this React Async instance, used in React DevTools (through `useDebugValue`) and React Async
443+
DevTools.
444+
437445
#### `defer`
438446

439447
> `boolean`

babel.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* eslint-disable no-console */
2+
console.log("Loaded babel.config.js")
3+
4+
module.exports = {
5+
presets: ["@babel/preset-env", "@babel/preset-react"],
6+
plugins: ["@babel/plugin-proposal-object-rest-spread"],
7+
8+
env: {
9+
test: {
10+
presets: ["@babel/preset-env", "@babel/preset-react"],
11+
plugins: ["@babel/plugin-transform-runtime"],
12+
},
13+
},
14+
}

jest.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* eslint-disable no-console */
2+
console.log("Loaded jest.config.js")
3+
4+
module.exports = {
5+
rootDir: "./",
6+
collectCoverage: true,
7+
coverageDirectory: "<rootDir>/coverage",
8+
verbose: true,
9+
bail: true,
10+
transform: { "^.+\\.js$": "babel-jest" },
11+
projects: ["<rootDir>/packages/*"],
12+
setupFiles: ["<rootDir>/jest.setup.js"],
13+
}

jest.setup.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* eslint-disable no-console */
2+
3+
/**
4+
* This is just a little hack to silence a warning that we'll get until react fixes this
5+
* @see https://github.com/facebook/react/pull/14853
6+
*/
7+
8+
console.log("Loaded jest.setup.js")
9+
10+
const originalError = console.error
11+
12+
beforeAll(() => {
13+
console.error = (...args) => {
14+
if (/Warning.*not wrapped in act/.test(args[0])) {
15+
return
16+
}
17+
originalError.call(console, ...args)
18+
}
19+
})
20+
21+
afterAll(() => {
22+
console.error = originalError
23+
})

0 commit comments

Comments
 (0)