Skip to content

Commit 6f5cc0d

Browse files
committed
Added Prettier. Updated Flow. Fixed some FlowTypes. Cleaned up unnecessary dependencies.
1 parent b86306b commit 6f5cc0d

File tree

7 files changed

+534
-479
lines changed

7 files changed

+534
-479
lines changed

.flowconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ node_modules/.*
88
[options]
99

1010
[lints]
11+
12+
[version]
13+
^0.57.3

.prettierrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"bracketSpacing": false,
3+
"jsxBracketSameLine": true,
4+
"parser": "flow",
5+
"printWidth": 80,
6+
"singleQuote": true,
7+
"trailingComma": "all"
8+
}

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@
1717
"clean:umd": "rimraf dist/umd",
1818
"flow": "flow check src",
1919
"lint": "eslint 'src/**/*.js'",
20+
"prettier": "prettier --config .prettierrc --write \"src/**/*.js\"",
2021
"test": "echo \"Error: no test specified\" && exit 1"
2122
},
2223
"author": "Brian Vaughn <brian.david.vaughn@gmail.com>",
2324
"license": "MIT",
2425
"devDependencies": {
2526
"babel-cli": "^6.24.1",
27+
"babel-core": "^6.25.0",
28+
"babel-loader": "^7.1.1",
2629
"babel-plugin-flow-react-proptypes": "^3.4.2",
2730
"babel-plugin-transform-react-remove-prop-types": "^0.4.6",
2831
"babel-plugin-transform-runtime": "^6.23.0",
@@ -31,16 +34,13 @@
3134
"babel-preset-es2015-rollup": "^3.0.0",
3235
"babel-preset-react": "^6.24.1",
3336
"babel-preset-stage-1": "^6.24.1",
37+
"babel-runtime": "^6.23.0",
3438
"cross-env": "^5.0.1",
3539
"eslint": "^4.2.0",
36-
"flow-cli": "^0.0.0-pre",
37-
"rimraf": "^2.6.1"
38-
},
39-
"dependencies": {
40-
"babel-core": "^6.25.0",
41-
"babel-loader": "^7.1.1",
42-
"babel-runtime": "^6.23.0",
40+
"flow-bin": "^0.57.3",
41+
"prettier": "^1.7.4",
4342
"prop-types": "^15.5.10",
43+
"rimraf": "^2.6.1",
4444
"webpack": "^3.3.0"
4545
},
4646
"peerDependencies": {

src/ErrorBoundary.js

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
/** @flow */
22

3-
import React, { Component } from 'react';
3+
import React, {Component} from 'react';
44
import ErrorBoundaryFallbackComponent from './ErrorBoundaryFallbackComponent';
55

6+
import type {ComponentType} from 'react';
7+
68
type Props = {
79
children?: any,
8-
FallbackComponent: any,
10+
FallbackComponent: ComponentType<any>,
911
onError?: (error: Error, componentStack: string) => void,
1012
};
1113

@@ -19,25 +21,16 @@ type State = {
1921
};
2022

2123
class ErrorBoundary extends Component<Props, State> {
22-
props: Props;
23-
state: State;
24-
25-
setState: Function
26-
2724
static defaultProps = {
2825
FallbackComponent: ErrorBoundaryFallbackComponent,
2926
};
3027

31-
constructor(props: Props, context: any) {
32-
super(props, context);
33-
34-
this.state = {
35-
error: null,
36-
info: null,
37-
};
38-
}
28+
state = {
29+
error: null,
30+
info: null,
31+
};
3932

40-
componentDidCatch(error: Error, info: ErrorInfo):void {
33+
componentDidCatch(error: Error, info: ErrorInfo): void {
4134
const {onError} = this.props;
4235

4336
if (typeof onError === 'function') {
@@ -55,24 +48,25 @@ class ErrorBoundary extends Component<Props, State> {
5548

5649
if (error !== null) {
5750
return (
58-
<FallbackComponent componentStack={info ? info.componentStack : ''} error={error} />
51+
<FallbackComponent
52+
componentStack={info ? info.componentStack : ''}
53+
error={error}
54+
/>
5955
);
6056
}
6157

6258
return children;
6359
}
6460
}
6561

66-
67-
export const withErrorBoundary: Function = (
68-
Component: Class<React.Component<*>>,
69-
FallbackComponent: Class<React.Component<*>>,
70-
onError: Function
62+
export const withErrorBoundary = (
63+
Component: ComponentType<any>,
64+
FallbackComponent: ComponentType<any>,
65+
onError: Function,
7166
): Function => props => (
72-
<ErrorBoundary FallbackComponent={FallbackComponent} onError={onError}>
73-
<Component {...props} />
74-
</ErrorBoundary>
75-
);
76-
67+
<ErrorBoundary FallbackComponent={FallbackComponent} onError={onError}>
68+
<Component {...props} />
69+
</ErrorBoundary>
70+
);
7771

7872
export default ErrorBoundary;

src/ErrorBoundaryFallbackComponent.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@ const toTitle = (error: Error, componentStack: string): string => {
1111
return `${error.toString()}\n\nThis is located at:${componentStack}`;
1212
};
1313

14-
const ErrorBoundaryFallbackComponent = ({ componentStack, error }: Props) => (
14+
const ErrorBoundaryFallbackComponent = ({componentStack, error}: Props) => (
1515
<div style={style} title={toTitle(error, componentStack)}>
1616
<svg style={svgStyle} viewBox="0 0 24 24" preserveAspectRatio="xMidYMid">
17-
<path d={`M20,12A8,8 0 0,0 12,4A8,8 0 0,0 4,12A8,8 0 0,0 12,20A8,8 0 0,0 20,
17+
<path
18+
d={`M20,12A8,8 0 0,0 12,4A8,8 0 0,0 4,12A8,8 0 0,0 12,20A8,8 0 0,0 20,
1819
12M22,12A10,10 0 0,1 12,22A10,10 0 0,1 2,12A10,10 0 0,1 12,2A10,10 0 0,1 22,
1920
12M15.5,8C16.3,8 17,8.7 17,9.5C17,10.3 16.3,11 15.5,11C14.7,11 14,10.3 14,
2021
9.5C14,8.7 14.7,8 15.5,8M10,9.5C10,10.3 9.3,11 8.5,11C7.7,11 7,10.3 7,9.5C7,
2122
8.7 7.7,8 8.5,8C9.3,8 10,8.7 10,9.5M12,14C13.75,14 15.29,14.72 16.19,
2223
15.81L14.77,17.23C14.32,16.5 13.25,16 12,16C10.75,16 9.68,16.5 9.23,
23-
17.23L7.81,15.81C8.71,14.72 10.25,14 12,14Z`} />
24+
17.23L7.81,15.81C8.71,14.72 10.25,14 12,14Z`}
25+
/>
2426
</svg>
2527
</div>
2628
);
@@ -45,4 +47,4 @@ const svgStyle = {
4547
flex: '1 1 auto',
4648
};
4749

48-
export default ErrorBoundaryFallbackComponent;
50+
export default ErrorBoundaryFallbackComponent;

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @flow */
22

33
import ErrorBoundaryFallbackComponent from './ErrorBoundaryFallbackComponent';
4-
import ErrorBoundary, { withErrorBoundary } from './ErrorBoundary';
4+
import ErrorBoundary, {withErrorBoundary} from './ErrorBoundary';
55

66
export default ErrorBoundary;
77
export {ErrorBoundary, withErrorBoundary, ErrorBoundaryFallbackComponent};

0 commit comments

Comments
 (0)