Skip to content

Commit af39ac1

Browse files
committed
async examples
1 parent c03da04 commit af39ac1

File tree

8 files changed

+93
-33
lines changed

8 files changed

+93
-33
lines changed

examples/async-components/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"start": "webpack-dev-server --hot"
77
},
88
"devDependencies": {
9+
"@hot-loader/react-dom": "^16.7.0-alpha.2.1",
910
"babel-core": "^6.26.0",
1011
"babel-loader": "^7.1.2",
1112
"babel-plugin-transform-class-properties": "^6.24.1",
@@ -23,7 +24,7 @@
2324
"react-async-component": "^2.0.0",
2425
"react-dom": "^16.4.1",
2526
"react-emotion": "^8.0.12",
26-
"react-hot-loader": "^4.1.1",
27+
"react-hot-loader": "^4.5.2",
2728
"react-imported-component": "^5.2.0",
2829
"react-loadable": "^5.5.0",
2930
"react-remock": "^0.2.1",

examples/async-components/src/App.js

+19-18
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import * as React from 'react'
33
import styled from 'styled-components'
44
import emoStyled from 'react-emotion'
55

6-
import CAsync from './chunks/async-component'
7-
import CLoadableComp from './chunks/loadable-components'
8-
import CLoadable from './chunks/react-loadable'
9-
import CImp from './chunks/react-imported-component'
10-
import CUni from './chunks/react-universal-component'
6+
// import CAsync from './chunks/async-component'
7+
// import CLoadableComp from './chunks/loadable-components'
8+
import { RLoadable1, RLoadable2 } from './chunks/react-loadable'
9+
// import CImp from './chunks/react-imported-component'
10+
// import CUni from './chunks/react-universal-component'
1111

1212
const BigText = styled.div`
1313
font-size: 20px;
@@ -29,21 +29,22 @@ const App = () => (
2929
<div>
3030
Testing React-Hot-Loader againts "React code splitting" components
3131
<ul>
32+
{/*<li>*/}
33+
{/*Async-components <CAsync />*/}
34+
{/*</li>*/}
35+
{/*<li>*/}
36+
{/*Loadable-components <CLoadableComp />*/}
37+
{/*</li>*/}
3238
<li>
33-
Async-components <CAsync />
34-
</li>
35-
<li>
36-
Loadable-components <CLoadableComp />
37-
</li>
38-
<li>
39-
React-Loadable <CLoadable />
40-
</li>
41-
<li>
42-
Imported-component <CImp />
43-
</li>
44-
<li>
45-
Universal-component <CUni />
39+
React-Loadable <RLoadable1 />
40+
1
4641
</li>
42+
{/*<li>*/}
43+
{/*Imported-component <CImp />*/}
44+
{/*</li>*/}
45+
{/*<li>*/}
46+
{/*Universal-component <CUni />*/}
47+
{/*</li>*/}
4748
</ul>
4849
</div>
4950
)

examples/async-components/src/Counter.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class Counter extends React.Component {
55
state = { count: 0 }
66

77
componentDidMount() {
8+
//
89
this.interval = setInterval(
910
() => this.setState(prevState => ({ count: prevState.count + 1 })),
1011
200,
@@ -16,8 +17,13 @@ class Counter extends React.Component {
1617
}
1718

1819
render() {
19-
return <div>#{this.state.count}</div>
20+
return (
21+
<div>
22+
1#{this.state.count}
23+
<span>5</span>
24+
</div>
25+
)
2026
}
2127
}
2228

23-
export default Counter //hot(module)(Counter)
29+
export default Counter
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react'
2+
import { hot } from 'react-hot-loader'
3+
4+
class Counter extends React.Component {
5+
state = { count: 0 }
6+
7+
componentDidMount() {
8+
//return;
9+
this.interval = setInterval(
10+
() => this.setState(prevState => ({ count: prevState.count + 2 })),
11+
200,
12+
)
13+
}
14+
15+
componentWillUnmount() {
16+
clearInterval(this.interval)
17+
}
18+
19+
render() {
20+
return <div>2#{this.state.count}</div>
21+
}
22+
}
23+
24+
export default Counter
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// import loadable from 'loadable-components' // this is old API
22
import loadable from '@loadable/component'
33

4-
export default loadable(() => import('../Counter'))
4+
export const Loadable1 = loadable(() => import('../Counter'))
5+
6+
export const Loadable2 = loadable(() => import('../Counter2'))
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import React from 'react'
22
import Loadable from 'react-loadable'
33

4-
export default Loadable({
4+
export const RLoadable1 = Loadable({
55
loader: () => import('../Counter'),
66
loading: () => <div />,
77
})
8+
9+
export const RLoadable2 = Loadable({
10+
loader: () => import('../Counter2'),
11+
loading: () => <div />,
12+
})

examples/async-components/webpack.config.babel.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = {
1212
module: {
1313
rules: [
1414
{
15-
//exclude: /node_modules|packages/, // should work without exclude
15+
exclude: /node_modules|packages/, // should work without exclude
1616
test: /\.js$/,
1717
use: 'babel-loader',
1818
},
@@ -22,6 +22,9 @@ module.exports = {
2222
extensions: ['.ts', '.tsx', '.js', '.jsx'],
2323
alias: {
2424
react: path.resolve(path.join(__dirname, './node_modules/react')),
25+
'react-dom': path.resolve(
26+
path.join(__dirname, './node_modules/@hot-loader/react-dom'),
27+
),
2528
'babel-core': path.resolve(
2629
path.join(__dirname, './node_modules/@babel/core'),
2730
),

examples/async-components/yarn.lock

+27-9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
lodash "^4.2.0"
2020
to-fast-properties "^2.0.0"
2121

22+
"@hot-loader/react-dom@^16.7.0-alpha.2.1":
23+
version "16.7.0-alpha.2.1"
24+
resolved "https://registry.yarnpkg.com/@hot-loader/react-dom/-/react-dom-16.7.0-alpha.2.1.tgz#c80fbb9b84b7b1d66377e6987a2bc2b3cde6f6b4"
25+
integrity sha512-Cyqqv4Lb2OU4Rs5poEsScO1qEMJyzs/77g5RLO0WF/qw6sT+blKs8AAQVoQJ5HHUMELBlncckBjF4ps0QLwQiA==
26+
2227
"@loadable/component@^4.0.2":
2328
version "4.0.2"
2429
resolved "https://registry.yarnpkg.com/@loadable/component/-/component-4.0.2.tgz#9e3f08e7c8ecf9a4733cc4ae760ae19596fad57d"
@@ -2992,6 +2997,11 @@ locate-path@^2.0.0:
29922997
p-locate "^2.0.0"
29932998
path-exists "^3.0.0"
29942999

3000+
lodash.merge@^4.6.1:
3001+
version "4.6.1"
3002+
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.1.tgz#adc25d9cb99b9391c59624f379fbba60d7111d54"
3003+
integrity sha512-AOYza4+Hf5z1/0Hztxpm2/xiPZgi/cjMqdnKTUWTBSKchJlxXXuUSxCCl8rJlf4g6yww/j6mA8nC8Hw/EZWxKQ==
3004+
29953005
lodash@^4.14.0, lodash@^4.17.2, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.2.0:
29963006
version "4.17.4"
29973007
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
@@ -3860,17 +3870,20 @@ react-emotion@^8.0.12:
38603870
babel-plugin-emotion "^8.0.12"
38613871
emotion-utils "^8.0.12"
38623872

3863-
react-hot-loader@^4.1.1:
3864-
version "4.1.1"
3865-
resolved "https://registry.yarnpkg.com/react-hot-loader/-/react-hot-loader-4.1.1.tgz#693499a6414b6dc6880287e254322a9d3155e944"
3866-
integrity sha512-bwDWesjqXABplFfqNOC6imbmW9y1JtT5RAo+hdIJ4OW2FsU48nrVzFiG8z9a+eB3Xd0C+KzFwD8aq31M+6SYKQ==
3873+
react-hot-loader@^4.5.2:
3874+
version "4.5.2"
3875+
resolved "https://registry.yarnpkg.com/react-hot-loader/-/react-hot-loader-4.5.2.tgz#5a91984196fb72801a52c62bfad0eb2322d7bcd3"
3876+
integrity sha512-R/mYorMt2YC9IkF/bpJqiYezrz5z1F7F+W1XIaiGezeuonQWIRpNycZRobkYHJNz66QKq6eBWeUYV6/AMmfaLw==
38673877
dependencies:
38683878
fast-levenshtein "^2.0.6"
38693879
global "^4.3.0"
38703880
hoist-non-react-statics "^2.5.0"
3881+
loader-utils "^1.1.0"
3882+
lodash.merge "^4.6.1"
38713883
prop-types "^15.6.1"
3872-
react-lifecycles-compat "^2.0.0"
3884+
react-lifecycles-compat "^3.0.4"
38733885
shallowequal "^1.0.2"
3886+
source-map "^0.7.3"
38743887

38753888
react-imported-component@^5.2.0:
38763889
version "5.2.0"
@@ -3887,10 +3900,10 @@ react-is@^16.3.2:
38873900
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.6.1.tgz#f77b1c3d901be300abe8d58645b7a59e794e5982"
38883901
integrity sha512-wOKsGtvTMYs7WAscmwwdM8sfRRvE17Ym30zFj3n37Qx5tHRfhenPKEPILHaHob6WoLFADmQm1ZNrE5xMCM6sCw==
38893902

3890-
react-lifecycles-compat@^2.0.0:
3891-
version "2.0.2"
3892-
resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-2.0.2.tgz#00a23160eec17a43b94dd74f95d44a1a2c3c5ec1"
3893-
integrity sha512-BPksUj7VMAAFhcCw79sZA0Ow/LTAEjs3Sio1AQcuwLeOP+ua0f/08Su2wyiW+JjDDH6fRqNy3h5CLXh21u1mVg==
3903+
react-lifecycles-compat@^3.0.4:
3904+
version "3.0.4"
3905+
resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362"
3906+
integrity sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA==
38943907

38953908
react-loadable@^5.5.0:
38963909
version "5.5.0"
@@ -4337,6 +4350,11 @@ [email protected], source-map@^0.5.3, source-map@^0.5.6, source-map@^0.5.7, sourc
43374350
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"
43384351
integrity sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=
43394352

4353+
source-map@^0.7.3:
4354+
version "0.7.3"
4355+
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.3.tgz#5302f8169031735226544092e64981f751750383"
4356+
integrity sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==
4357+
43404358
source-map@~0.6.1:
43414359
version "0.6.1"
43424360
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"

0 commit comments

Comments
 (0)