Skip to content

Commit 39d04ad

Browse files
committedMar 22, 2018
Updates to react-async-bootstrapper v2.
Errors now get rendered inline.
1 parent 57d801d commit 39d04ad

13 files changed

+1038
-530
lines changed
 

‎.babelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"presets": [["env", { "targets": { "node": true } }], "stage-3", "react"]
2+
"presets": [["env", { "targets": { "node": true } }], "stage-3", "react"],
3+
"plugins": ["transform-class-properties"]
34
}

‎package.json

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
{
22
"name": "react-async-component",
33
"version": "1.0.2",
4-
"description":
5-
"Create Components that resolve asynchronously, with support for server side rendering and code splitting.",
4+
"description": "Create Components that resolve asynchronously, with support for server side rendering and code splitting.",
65
"license": "MIT",
76
"main": "commonjs/index.js",
8-
"files": ["index.d.ts", "*.js", "*.md", "dist"],
7+
"files": [
8+
"index.d.ts",
9+
"*.js",
10+
"*.md",
11+
"dist"
12+
],
913
"typings": "./index.d.ts",
1014
"repository": {
1115
"type": "git",
@@ -22,8 +26,7 @@
2226
],
2327
"scripts": {
2428
"build": "node ./tools/scripts/build.js",
25-
"clean":
26-
"rimraf ./commonjs && rimraf ./umd && rimraf ./coverage && rimraf ./umd",
29+
"clean": "rimraf ./commonjs && rimraf ./umd && rimraf ./coverage && rimraf ./umd",
2730
"lint": "eslint src",
2831
"precommit": "lint-staged && npm run test",
2932
"prepublish": "npm run build",
@@ -32,16 +35,16 @@
3235
"test:coverage:deploy": "npm run test:coverage && codecov"
3336
},
3437
"peerDependencies": {
38+
"prop-types": "^15.0.0",
3539
"react": "^0.14.0 || ^15.0.0 || ^16.0.0",
36-
"react-dom": "^0.14.0 || ^15.0.0 || ^16.0.0",
37-
"prop-types": "^15.0.0"
40+
"react-dom": "^0.14.0 || ^15.0.0 || ^16.0.0"
3841
},
3942
"devDependencies": {
4043
"app-root-dir": "1.0.2",
4144
"babel-cli": "^6.26.0",
4245
"babel-core": "^6.26.0",
4346
"babel-eslint": "^8.0.1",
44-
"babel-jest": "^21.2.0",
47+
"babel-jest": "^22.4.3",
4548
"babel-loader": "^7.1.2",
4649
"babel-plugin-external-helpers": "^6.22.0",
4750
"babel-plugin-transform-class-properties": "^6.24.1",
@@ -65,29 +68,38 @@
6568
"gzip-size": "^4.0.0",
6669
"husky": "^0.14.3",
6770
"in-publish": "2.0.0",
68-
"jest": "^21.2.1",
69-
"lint-staged": "^4.2.3",
71+
"jest": "^22.4.3",
72+
"lint-staged": "^7.0.0",
7073
"memory-fs": "0.4.1",
7174
"prettier": "^1.7.4",
7275
"pretty-bytes": "4.0.2",
7376
"prop-types": "^15.6.0",
7477
"raf": "^3.4.0",
7578
"ramda": "^0.25.0",
7679
"react": "^16.0.0",
77-
"react-async-bootstrapper": "^1.1.2",
80+
"react-async-bootstrapper": "^2.1.0",
7881
"react-dom": "^16.0.0",
7982
"react-test-renderer": "^16.0.0",
80-
"readline-sync": "1.4.7",
83+
"readline-sync": "1.4.9",
8184
"rimraf": "^2.6.2",
82-
"rollup": "^0.56.5",
85+
"rollup": "^0.57.1",
8386
"rollup-plugin-babel": "^3.0.3",
8487
"rollup-plugin-uglify": "^3.0.0"
8588
},
8689
"jest": {
87-
"collectCoverageFrom": ["src/**/*.{js,jsx}"],
88-
"setupFiles": ["raf/polyfill", "<rootDir>/tools/tests/setup.js"],
89-
"snapshotSerializers": ["<rootDir>/node_modules/enzyme-to-json/serializer"],
90-
"testPathIgnorePatterns": ["<rootDir>/(coverage|dist|node_modules|tools)/"]
90+
"collectCoverageFrom": [
91+
"src/**/*.{js,jsx}"
92+
],
93+
"setupFiles": [
94+
"raf/polyfill",
95+
"<rootDir>/tools/tests/setup.js"
96+
],
97+
"snapshotSerializers": [
98+
"<rootDir>/node_modules/enzyme-to-json/serializer"
99+
],
100+
"testPathIgnorePatterns": [
101+
"<rootDir>/(coverage|dist|node_modules|tools)/"
102+
]
91103
},
92104
"eslintConfig": {
93105
"root": true,
@@ -98,7 +110,10 @@
98110
"node": true,
99111
"jest": true
100112
},
101-
"extends": ["airbnb", "prettier"],
113+
"extends": [
114+
"airbnb",
115+
"prettier"
116+
],
102117
"rules": {
103118
"camelcase": 0,
104119
"import/prefer-default-export": 0,
@@ -107,19 +122,29 @@
107122
"no-underscore-dangle": 0,
108123
"react/no-array-index-key": 0,
109124
"react/react-in-jsx-scope": 0,
110-
"semi": [2, "never"],
125+
"semi": [
126+
2,
127+
"never"
128+
],
111129
"react/forbid-prop-types": 0,
112130
"react/jsx-filename-extension": 0,
113131
"react/sort-comp": 0
114132
}
115133
},
116-
"eslintIgnore": ["node_modules/", "coverage/", "dist/"],
134+
"eslintIgnore": [
135+
"node_modules/",
136+
"coverage/",
137+
"dist/"
138+
],
117139
"prettier": {
118140
"semi": false,
119141
"singleQuote": true,
120142
"trailingComma": "all"
121143
},
122144
"lint-staged": {
123-
"*.js": ["prettier --write \"src/**/*.js\"", "git add"]
145+
"*.js": [
146+
"prettier --write \"src/**/*.js\"",
147+
"git add"
148+
]
124149
}
125150
}

‎rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = {
2020
babelrc: false,
2121
exclude: 'node_modules/**',
2222
presets: [['env', { modules: false }], 'stage-3', 'react'],
23-
plugins: ['external-helpers'],
23+
plugins: ['transform-class-properties', 'external-helpers'],
2424
}),
2525
],
2626
}

‎src/AsyncComponentProvider.js

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,39 @@
1-
import React from 'react'
1+
import React, { Component } from 'react'
22
import PropTypes from 'prop-types'
33

44
import createAsyncContext from './createAsyncContext'
55

6-
class AsyncComponentProvider extends React.Component {
6+
export default class AsyncComponentProvider extends Component {
7+
static propTypes = {
8+
children: PropTypes.node.isRequired,
9+
asyncContext: PropTypes.shape({
10+
getNextId: PropTypes.func.isRequired,
11+
resolved: PropTypes.func.isRequired,
12+
failed: PropTypes.func.isRequired,
13+
getState: PropTypes.func.isRequired,
14+
}),
15+
rehydrateState: PropTypes.shape({
16+
resolved: PropTypes.object,
17+
}),
18+
}
19+
20+
static defaultProps = {
21+
asyncContext: undefined,
22+
rehydrateState: {
23+
resolved: {},
24+
},
25+
}
26+
27+
static childContextTypes = {
28+
asyncComponents: PropTypes.shape({
29+
getNextId: PropTypes.func.isRequired,
30+
resolved: PropTypes.func.isRequired,
31+
failed: PropTypes.func.isRequired,
32+
shouldRehydrate: PropTypes.func.isRequired,
33+
getError: PropTypes.func.isRequired,
34+
}).isRequired,
35+
}
36+
737
componentWillMount() {
838
this.asyncContext = this.props.asyncContext || createAsyncContext()
939
this.rehydrateState = this.props.rehydrateState
@@ -14,11 +44,14 @@ class AsyncComponentProvider extends React.Component {
1444
asyncComponents: {
1545
getNextId: this.asyncContext.getNextId,
1646
resolved: this.asyncContext.resolved,
47+
failed: this.asyncContext.failed,
1748
shouldRehydrate: id => {
1849
const resolved = this.rehydrateState.resolved[id]
1950
delete this.rehydrateState.resolved[id]
2051
return resolved
2152
},
53+
getError: id =>
54+
this.rehydrateState.errors && this.rehydrateState.errors[id],
2255
},
2356
}
2457
}
@@ -27,32 +60,3 @@ class AsyncComponentProvider extends React.Component {
2760
return React.Children.only(this.props.children)
2861
}
2962
}
30-
31-
AsyncComponentProvider.propTypes = {
32-
children: PropTypes.node.isRequired,
33-
asyncContext: PropTypes.shape({
34-
getNextId: PropTypes.func.isRequired,
35-
resolved: PropTypes.func.isRequired,
36-
getState: PropTypes.func.isRequired,
37-
}),
38-
rehydrateState: PropTypes.shape({
39-
resolved: PropTypes.object,
40-
}),
41-
}
42-
43-
AsyncComponentProvider.defaultProps = {
44-
asyncContext: undefined,
45-
rehydrateState: {
46-
resolved: {},
47-
},
48-
}
49-
50-
AsyncComponentProvider.childContextTypes = {
51-
asyncComponents: PropTypes.shape({
52-
getNextId: PropTypes.func.isRequired,
53-
resolved: PropTypes.func.isRequired,
54-
shouldRehydrate: PropTypes.func.isRequired,
55-
}).isRequired,
56-
}
57-
58-
export default AsyncComponentProvider

0 commit comments

Comments
 (0)