Skip to content

Commit 4e3bf7f

Browse files
authored
Merge pull request #14 from xtuc/feat-dynamic-import
Improve dynamic import support
2 parents da57ee8 + 882854e commit 4e3bf7f

File tree

14 files changed

+253
-11
lines changed

14 files changed

+253
-11
lines changed

examples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
## React
22

33
- [Basic example](https://github.com/xtuc/async-reactor/tree/master/examples/React-basic)
4+
- [Dynamic import example](https://github.com/xtuc/async-reactor/tree/master/examples/React-dynamic-import)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/coverage
2+
/dist
3+
/node_modules
4+
npm-debug.log*
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# React
2+
3+
## Prerequisites
4+
5+
[Node.js](http://nodejs.org/) >= v4 must be installed.
6+
7+
## Installation
8+
9+
- Running `npm install` in the app's root directory will install everything you need for development.
10+
11+
## Development Server
12+
13+
- `npm start` will run the app's development server at [http://localhost:3000](http://localhost:3000) with hot module reloading.
14+
15+
## Running Tests
16+
17+
- `npm test` will run the tests once.
18+
19+
- `npm run test:coverage` will run the tests and produce a coverage report in `coverage/`.
20+
21+
- `npm run test:watch` will run the tests on every change.
22+
23+
## Building
24+
25+
- `npm run build` creates a production build by default.
26+
27+
To create a development build, set the `NODE_ENV` environment variable to `development` while running this command.
28+
29+
- `npm run clean` will delete built resources.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
type: 'react-app'
3+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "React",
3+
"version": "1.0.0",
4+
"description": "Async-reactor in React example",
5+
"private": true,
6+
"scripts": {
7+
"build": "nwb build-react-app",
8+
"clean": "nwb clean-app",
9+
"start": "nwb serve-react-app",
10+
"test": "nwb test-react",
11+
"test:coverage": "nwb test-react --coverage",
12+
"test:watch": "nwb test-react --server"
13+
},
14+
"dependencies": {
15+
"async-reactor": "^1.0.4",
16+
"react": "^15.5.4",
17+
"react-dom": "^15.5.4"
18+
},
19+
"devDependencies": {
20+
"nwb": "0.15.x"
21+
},
22+
"author": "Sven SAULEAU",
23+
"license": "MIT",
24+
"repository": {
25+
"type": "git",
26+
"url": "https://github.com/xtuc/async-reactor-examples.git"
27+
}
28+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.container {
2+
width: 500px;
3+
background-color: white;
4+
margin: 20px auto;
5+
}
6+
7+
.box {
8+
box-shadow: 0 4px 5px 0 rgba(0,0,0,.14), 0 1px 10px 0 rgba(0,0,0,.12), 0 2px 4px -1px rgba(0,0,0,.2);
9+
border-radius: 2px;
10+
padding: 80px 56px;
11+
padding-bottom: 30px;
12+
margin: 30px;
13+
}
14+
15+
h2 {
16+
font-weight: 500;
17+
color: rgb(255,64,129);
18+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import './App.css';
2+
3+
import React from 'react'
4+
import {asyncReactor} from 'async-reactor';
5+
6+
function Loader() {
7+
8+
return (
9+
<div className='container'>
10+
<div className='box'>
11+
<h2>Loading ...</h2>
12+
</div>
13+
</div>
14+
);
15+
}
16+
17+
const Post = asyncReactor(import('./Components/Post'), Loader);
18+
19+
async function AsyncPosts() {
20+
const Container = (await import('./Components/Container')).default;
21+
22+
const data = await fetch('https://jsonplaceholder.typicode.com/posts');
23+
const posts = await data.json();
24+
25+
return (
26+
<Container>
27+
{posts.map((post) => (
28+
<Post title={post.title} body={post.body} key={post.id} />
29+
))}
30+
</Container>
31+
);
32+
}
33+
34+
export default asyncReactor(AsyncPosts, Loader);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react';
2+
3+
export default function Container({children}) {
4+
5+
return (
6+
<div className="container">
7+
{children}
8+
</div>
9+
);
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react'
2+
3+
export default function Post({title, body}) {
4+
return (
5+
<article className="box">
6+
<h2>{title}</h2>
7+
8+
<p>{body}</p>
9+
</article>
10+
);
11+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
6+
<meta http-equiv="x-ua-compatible" content="ie=edge">
7+
<title>React</title>
8+
<meta name="description" content="">
9+
</head>
10+
<body>
11+
<div id="app"></div>
12+
</body>
13+
</html>

0 commit comments

Comments
 (0)