Skip to content

Commit d864c00

Browse files
committed
Cleans up project.
Removes flow. Adds prettier and eslint-prettier. 😍
1 parent 62a34c8 commit d864c00

18 files changed

+457
-467
lines changed

.eslintrc

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
"root": true,
33
"parser": "babel-eslint",
44
"extends": "airbnb",
5-
"plugins": [
6-
"flowtype"
7-
],
5+
"plugins": [],
86
"env": {
97
"browser": true,
108
"es6": true,

.flowconfig

-45
This file was deleted.

package.json

+13-14
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,23 @@
2424
"webpack"
2525
],
2626
"scripts": {
27+
"precommit": "lint-staged && npm run test",
2728
"build": "babel-node ./tools/scripts/build.js",
2829
"check": "yarn run lint && yarn run test",
2930
"clean": "rimraf ./commonjs && rimraf ./umd && rimraf ./coverage && rimraf ./flow-coverage && rimraf ./umd",
3031
"example:web": "echo 'Make sure to `cd example/web && yarn install`' && cd example/web && yarn run start",
31-
"flow": "babel-node ./tools/scripts/flow",
32-
"flow:coverage": "flow-coverage-report -i 'src/**/*.js' -t html -t json -t text",
33-
"flow:defs": "flow-typed install --overwrite",
34-
"lint": "eslint src",
32+
"lint": "eslint src,tools",
3533
"prepublish": "yarn run build",
3634
"test": "jest",
3735
"test:coverage": "yarn run test -- --coverage",
3836
"test:coverage:deploy": "yarn run test:coverage && codecov"
3937
},
38+
"lint-staged": {
39+
"*.js": [
40+
"prettier-eslint --write",
41+
"git add"
42+
]
43+
},
4044
"peerDependencies": {
4145
"react": "^0.14.0 || ^15.0.0-0",
4246
"react-dom": "^0.14.0 || ^15.0.0-0"
@@ -63,17 +67,17 @@
6367
"enzyme-to-json": "1.5.0",
6468
"eslint": "3.17.1",
6569
"eslint-config-airbnb": "14.1.0",
66-
"eslint-plugin-flowtype": "2.30.3",
6770
"eslint-plugin-import": "2.2.0",
6871
"eslint-plugin-jsx-a11y": "4.0.0",
6972
"eslint-plugin-react": "6.10.0",
70-
"flow-bin": "0.41.0",
71-
"flow-coverage-report": "0.3.0",
72-
"flow-typed": "2.0.0",
73-
"ghooks": "2.0.0",
7473
"gzip-size": "3.0.0",
74+
"husky": "0.13.2",
7575
"in-publish": "2.0.0",
7676
"jest": "19.0.2",
77+
"lint-staged": "3.4.0",
78+
"prettier": "0.22.0",
79+
"prettier-eslint": "4.2.1",
80+
"prettier-eslint-cli": "^3.1.2",
7781
"pretty-bytes": "4.0.2",
7882
"ramda": "0.23.0",
7983
"react": "15.4.2",
@@ -86,11 +90,6 @@
8690
"webpack-dev-middleware": "1.10.1",
8791
"webpack-hot-middleware": "2.17.1"
8892
},
89-
"config": {
90-
"ghooks": {
91-
"pre-commit": "yarn run check"
92-
}
93-
},
9493
"jest": {
9594
"collectCoverageFrom": [
9695
"src/**/*.{js,jsx}"

src/AsyncComponentProvider.js

+2-14
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
1-
/* @flow */
2-
31
import React from 'react'
4-
import type { ExecContext, ProviderChildContext } from './types'
52

63
import createContext from './createContext'
74

8-
type Props = {
9-
// eslint-disable-next-line
10-
children?: any,
11-
execContext?: ExecContext,
12-
};
13-
145
class AsyncComponentProvider extends React.Component {
15-
props: Props
16-
execContext: ExecContext
17-
18-
constructor(props : Props, context : Object) {
6+
constructor(props, context) {
197
super(props, context)
208

219
this.execContext = props.execContext || createContext()
2210
}
2311

24-
getChildContext() : ProviderChildContext {
12+
getChildContext() {
2513
return {
2614
asyncComponents: {
2715
getNextId: this.execContext.getNextId,

src/__tests__/integration.test.js

+20-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* @flow */
2-
31
import React from 'react'
42
import { renderToStaticMarkup } from 'react-dom/server'
53
import { mount } from 'enzyme'
@@ -13,7 +11,7 @@ import {
1311
} from '../'
1412

1513
function Bob({ children }) {
16-
return (<div>{children}</div>)
14+
return <div>{children}</div>
1715
}
1816
Bob.propTypes = { children: React.PropTypes.node }
1917
Bob.defaultProps = { children: null }
@@ -56,7 +54,9 @@ const app = execContext => (
5654
<span>In Defer.</span>
5755
</DeferredAsyncBob>
5856
<BoundaryAsyncBob>
59-
<span>In Boundary but outside an AsyncComponent, server render me!</span>
57+
<span>
58+
In Boundary but outside an AsyncComponent, server render me!
59+
</span>
6060
<AsyncBobThree>
6161
<span>In Boundary - Do not server render me!</span>
6262
</AsyncBobThree>
@@ -93,21 +93,22 @@ describe('integration tests', () => {
9393
// "Client" side render...
9494
const clientContext = createContext()
9595
const clientApp = app(clientContext)
96-
return withAsyncComponents(clientApp)
97-
.then(() => {
98-
const clientRenderWrapper = mount(clientApp)
99-
expect(clientRenderWrapper).toMatchSnapshot()
100-
expect(renderToStaticMarkup(clientApp)).toEqual(serverHTML)
101-
return clientRenderWrapper
102-
})
103-
// Now give the client side components time to resolve
104-
.then(clientRenderWrapper => new Promise(resolve =>
105-
setTimeout(() => resolve(clientRenderWrapper), 100),
106-
))
107-
// Now a full render should have occured on client
108-
.then(clientRenderWrapper =>
109-
expect(clientRenderWrapper).toMatchSnapshot(),
110-
)
96+
return (
97+
withAsyncComponents(clientApp)
98+
.then(() => {
99+
const clientRenderWrapper = mount(clientApp)
100+
expect(clientRenderWrapper).toMatchSnapshot()
101+
expect(renderToStaticMarkup(clientApp)).toEqual(serverHTML)
102+
return clientRenderWrapper
103+
})
104+
// Now give the client side components time to resolve
105+
.then(
106+
clientRenderWrapper =>
107+
new Promise(resolve => setTimeout(() => resolve(clientRenderWrapper), 100)),
108+
)
109+
// Now a full render should have occured on client
110+
.then(clientRenderWrapper => expect(clientRenderWrapper).toMatchSnapshot())
111+
)
111112
})
112113
})
113114

src/constants.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* @flow */
21
/* eslint-disable import/prefer-default-export */
32

43
export const STATE_IDENTIFIER = '__REACT_ASYNC_COMPONENTS_STATE__'

src/index.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* @flow */
2-
31
import AsyncComponentProvider from './AsyncComponentProvider'
42
import createContext from './createContext'
53
import createAsyncComponent from './createAsyncComponent'

src/types.js

-18
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,2 @@
1-
/* @flow */
2-
31
// eslint-disable-next-line import/no-extraneous-dependencies
42
import { Element } from 'react'
5-
6-
export type React$Element = Element<*>;
7-
8-
export type ExecContext = {
9-
getNextId : () => number,
10-
registerComponent : (number, Function) => void,
11-
getComponent : (number) => ?Function,
12-
getResolved : () => { [key : number] : true },
13-
}
14-
15-
export type ProviderChildContext = {
16-
asyncComponents: {
17-
getNextId : () => number,
18-
getComponent : (number) => ?Function,
19-
}
20-
};

src/withAsyncComponents.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
/* @flow */
2-
31
import reactTreeWalker from 'react-tree-walker'
42
import { STATE_IDENTIFIER } from './constants'
5-
import type { React$Element } from './types'
63

7-
export default function withAsyncComponents(app : React$Element) : Promise<any> {
4+
export default function withAsyncComponents(app) {
85
const isBrowser = typeof window !== 'undefined'
9-
const rehydrateState = isBrowser
10-
&& typeof window[STATE_IDENTIFIER] !== 'undefined'
6+
const rehydrateState = isBrowser && typeof window[STATE_IDENTIFIER] !== 'undefined'
117
? window[STATE_IDENTIFIER]
128
: null
139

@@ -36,7 +32,9 @@ export default function withAsyncComponents(app : React$Element) : Promise<any>
3632
return true
3733
}
3834

39-
return reactTreeWalker(app, visitor, {})
40-
// Swallow errors.
41-
.catch(() => undefined)
35+
return (
36+
reactTreeWalker(app, visitor, {})
37+
// Swallow errors.
38+
.catch(() => undefined)
39+
)
4240
}

tools/.eslintrc

-6
This file was deleted.

tools/scripts/build.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* @flow */
1+
/* */
22

33
import { readFileSync } from 'fs'
44
import { inInstall } from 'in-publish'
@@ -19,12 +19,8 @@ exec('cross-env BABEL_ENV=commonjs babel --ignore **/__tests__ ./src -d ./common
1919
exec('cross-env BABEL_ENV=umd webpack --config ./tools/webpack/umd.config.babel.js', nodeEnv)
2020
exec('cross-env BABEL_ENV=umd webpack --config ./tools/webpack/umd-min.config.babel.js', nodeEnv)
2121

22-
function fileGZipSize(path : string) : string {
23-
return pipe(
24-
readFileSync,
25-
gzipSizeSync,
26-
prettyBytes,
27-
)(path)
22+
function fileGZipSize(path) {
23+
return pipe(readFileSync, gzipSizeSync, prettyBytes)(path)
2824
}
2925

3026
const umdMinFilePath = `umd/${getPackageJson().name}.min.js`

tools/scripts/flow.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* @flow */
1+
/* */
22

33
// Runs flow type checking.
44

@@ -8,7 +8,9 @@ import appRootDir from 'app-root-dir'
88
import { exec } from '../utils'
99

1010
if (!existsSync(resolvePath(appRootDir.get(), './flow-typed'))) {
11-
console.warn('You haven\'t installed the flow-typed definitions. Please run the `npm run flow:defs` command if you would like to install them.')
11+
console.warn(
12+
"You haven't installed the flow-typed definitions. Please run the `npm run flow:defs` command if you would like to install them.",
13+
)
1214
}
1315

1416
try {

tools/tests/warningsToErrors.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
/* @flow */
1+
/* */
22

33
import sinon from 'sinon'
44

55
export default function warningsToErrors() {
66
// Ensure console.warnings become thrown errors.
77
beforeAll(() => {
8-
sinon.stub(console, 'error', (warning) => { throw new Error(warning) })
8+
sinon.stub(console, 'error', (warning) => {
9+
throw new Error(warning)
10+
})
911
})
1012

1113
// While not forgetting to restore it afterwards.
12-
afterAll(() => { console.error.restore() })
14+
afterAll(() => {
15+
console.error.restore()
16+
})
1317
}

tools/utils.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
/* @flow */
1+
/* */
22

33
import { execSync } from 'child_process'
44
import appRootDir from 'app-root-dir'
55
import { resolve as resolvePath } from 'path'
66
import { readFileSync } from 'fs'
77

8-
export function removeEmpty<A>(x : Array<A>) : Array<A> {
8+
export function removeEmpty(x) {
99
return x.filter(y => y != null)
1010
}
1111

@@ -35,19 +35,17 @@ export function removeEmpty<A>(x : Array<A>) : Array<A> {
3535
// then this function will only be interpretted after the ifElse has run. This
3636
// can be handy for values that require some complex initialization process.
3737
// e.g. ifDev(() => 'lazy', 'not lazy');
38-
export function ifElse(condition : boolean) {
39-
return function ifElseResolver<A, B>(then : A, or : B) : A|B {
40-
const execIfFuc = x => (typeof x === 'function' ? x() : x)
41-
return condition ? execIfFuc(then) : (or)
38+
export function ifElse(condition) {
39+
return function ifElseResolver(then, or) {
40+
const execIfFuc = x => typeof x === 'function' ? x() : x
41+
return condition ? execIfFuc(then) : or
4242
}
4343
}
4444

4545
export function getPackageJson() {
46-
return JSON.parse(
47-
readFileSync(resolvePath(appRootDir.get(), './package.json'), 'utf-8'),
48-
)
46+
return JSON.parse(readFileSync(resolvePath(appRootDir.get(), './package.json'), 'utf-8'))
4947
}
5048

51-
export function exec(command : string) {
49+
export function exec(command) {
5250
execSync(command, { stdio: 'inherit', cwd: appRootDir.get() })
5351
}

0 commit comments

Comments
 (0)