-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from xtuc/feat-dynamic-import
Improve dynamic import support
- Loading branch information
Showing
14 changed files
with
253 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
## React | ||
|
||
- [Basic example](https://github.com/xtuc/async-reactor/tree/master/examples/React-basic) | ||
- [Dynamic import example](https://github.com/xtuc/async-reactor/tree/master/examples/React-dynamic-import) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/coverage | ||
/dist | ||
/node_modules | ||
npm-debug.log* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# React | ||
|
||
## Prerequisites | ||
|
||
[Node.js](http://nodejs.org/) >= v4 must be installed. | ||
|
||
## Installation | ||
|
||
- Running `npm install` in the app's root directory will install everything you need for development. | ||
|
||
## Development Server | ||
|
||
- `npm start` will run the app's development server at [http://localhost:3000](http://localhost:3000) with hot module reloading. | ||
|
||
## Running Tests | ||
|
||
- `npm test` will run the tests once. | ||
|
||
- `npm run test:coverage` will run the tests and produce a coverage report in `coverage/`. | ||
|
||
- `npm run test:watch` will run the tests on every change. | ||
|
||
## Building | ||
|
||
- `npm run build` creates a production build by default. | ||
|
||
To create a development build, set the `NODE_ENV` environment variable to `development` while running this command. | ||
|
||
- `npm run clean` will delete built resources. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
type: 'react-app' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "React", | ||
"version": "1.0.0", | ||
"description": "Async-reactor in React example", | ||
"private": true, | ||
"scripts": { | ||
"build": "nwb build-react-app", | ||
"clean": "nwb clean-app", | ||
"start": "nwb serve-react-app", | ||
"test": "nwb test-react", | ||
"test:coverage": "nwb test-react --coverage", | ||
"test:watch": "nwb test-react --server" | ||
}, | ||
"dependencies": { | ||
"async-reactor": "^1.0.4", | ||
"react": "^15.5.4", | ||
"react-dom": "^15.5.4" | ||
}, | ||
"devDependencies": { | ||
"nwb": "0.15.x" | ||
}, | ||
"author": "Sven SAULEAU", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/xtuc/async-reactor-examples.git" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.container { | ||
width: 500px; | ||
background-color: white; | ||
margin: 20px auto; | ||
} | ||
|
||
.box { | ||
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); | ||
border-radius: 2px; | ||
padding: 80px 56px; | ||
padding-bottom: 30px; | ||
margin: 30px; | ||
} | ||
|
||
h2 { | ||
font-weight: 500; | ||
color: rgb(255,64,129); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import './App.css'; | ||
|
||
import React from 'react' | ||
import {asyncReactor} from 'async-reactor'; | ||
|
||
function Loader() { | ||
|
||
return ( | ||
<div className='container'> | ||
<div className='box'> | ||
<h2>Loading ...</h2> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
const Post = asyncReactor(import('./Components/Post'), Loader); | ||
|
||
async function AsyncPosts() { | ||
const Container = (await import('./Components/Container')).default; | ||
|
||
const data = await fetch('https://jsonplaceholder.typicode.com/posts'); | ||
const posts = await data.json(); | ||
|
||
return ( | ||
<Container> | ||
{posts.map((post) => ( | ||
<Post title={post.title} body={post.body} key={post.id} /> | ||
))} | ||
</Container> | ||
); | ||
} | ||
|
||
export default asyncReactor(AsyncPosts, Loader); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react'; | ||
|
||
export default function Container({children}) { | ||
|
||
return ( | ||
<div className="container"> | ||
{children} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react' | ||
|
||
export default function Post({title, body}) { | ||
return ( | ||
<article className="box"> | ||
<h2>{title}</h2> | ||
|
||
<p>{body}</p> | ||
</article> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
<meta http-equiv="x-ua-compatible" content="ie=edge"> | ||
<title>React</title> | ||
<meta name="description" content=""> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from 'react'; | ||
import {render} from 'react-dom'; | ||
import {asyncReactor} from 'async-reactor'; | ||
|
||
function Loader() { | ||
|
||
return ( | ||
<div className='container'> | ||
<div className='box'> | ||
<h2>Loading ...</h2> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
const App = asyncReactor(import('./App'), Loader); | ||
|
||
render(<App/>, document.querySelector('#app')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* @flow */ | ||
|
||
import {Component, createElement} from 'react'; | ||
|
||
export function createReactorElement( | ||
Reactor: any /* Component */, | ||
component: Function, | ||
loaderComponent: Component<any,any,any> | string = 'div' | ||
) { | ||
|
||
return function renderReactorElement(passthroughProps: Object = {}) { | ||
const props = { | ||
wait: component, | ||
loader: loaderComponent, | ||
passthroughProps: passthroughProps, | ||
}; | ||
|
||
return createElement(Reactor, props); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters