-
-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also update example
- Loading branch information
Showing
30 changed files
with
257 additions
and
98 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 |
---|---|---|
|
@@ -2,4 +2,3 @@ node_modules/ | |
/coverage/ | ||
/dist/ | ||
__fixtures__/ | ||
/example/ |
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,7 @@ | ||
module.exports = { | ||
rules: { | ||
'jsx-a11y/anchor-is-valid': 'off', | ||
'import/no-unresolved': 'off', | ||
'import/extensions': 'off', | ||
}, | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,46 @@ | ||
import React from 'react' | ||
import { hot } from 'react-hot-loader' | ||
import { Link, Route } from 'react-router-dom' | ||
import Home from './Home' | ||
import Nesting from './nesting/Nesting' | ||
import SameModules from './same-modules/SameModules' | ||
import MultipleLoad from './multiple-load/MultipleLoad' | ||
import HotReloadingSandbox from './hot-reloading-sandbox/HotReloadingSandbox' | ||
import AsyncMode from './async-mode/AsyncMode' | ||
|
||
const App = () => ( | ||
<div> | ||
<nav> | ||
<ul> | ||
<li> | ||
<Link to="/">Home</Link> | ||
</li> | ||
<li> | ||
<Link to="/nesting">Nesting</Link> | ||
</li> | ||
<li> | ||
<Link to="/same-modules">Same modules</Link> | ||
</li> | ||
<li> | ||
<Link to="/multiple-load">Multiple Load</Link> | ||
</li> | ||
<li> | ||
<Link to="/hot-reloading-sandbox">Hot Reloading Sandbox</Link> | ||
</li> | ||
<li> | ||
<Link to="/async-mode">Async Mode</Link> | ||
</li> | ||
</ul> | ||
</nav> | ||
<main> | ||
<Route exact path="/" component={Home} /> | ||
<Route path="/nesting" component={Nesting} /> | ||
<Route path="/same-modules" component={SameModules} /> | ||
<Route path="/multiple-load" component={MultipleLoad} /> | ||
<Route path="/hot-reloading-sandbox" component={HotReloadingSandbox} /> | ||
<Route path="/async-mode" component={AsyncMode} /> | ||
</main> | ||
</div> | ||
) | ||
|
||
export default hot(module)(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,3 @@ | ||
const Home = () => 'Welcome on Loadable Components examples' | ||
|
||
export default Home |
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 @@ | ||
import React, { Timeout } from 'react' | ||
import loadable from 'loadable-components' | ||
|
||
const AsyncWorld = loadable( | ||
() => | ||
import('./World').then( | ||
World => new Promise(resolve => setTimeout(() => resolve(World), 500)), | ||
), | ||
{ asyncMode: true }, | ||
) | ||
|
||
const AsyncMode = () => ( | ||
<React.Fragment> | ||
<Timeout ms={100}> | ||
{didTimeout => (didTimeout ? 'Loading...' : <AsyncWorld />)} | ||
</Timeout> | ||
</React.Fragment> | ||
) | ||
|
||
export default AsyncMode |
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 @@ | ||
export default () => 'World' |
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,9 +1,15 @@ | ||
/* eslint-env browser */ | ||
import ReactDOM from 'react-dom' | ||
import React from 'react' | ||
import { BrowserRouter } from 'react-router-dom' | ||
import { loadComponents } from 'loadable-components' | ||
import App from './App' | ||
|
||
loadComponents().then(() => { | ||
ReactDOM.hydrate(<App />, document.getElementById('root')) | ||
ReactDOM.hydrate( | ||
<BrowserRouter> | ||
<App /> | ||
</BrowserRouter>, | ||
document.getElementById('root'), | ||
) | ||
}) |
File renamed without changes.
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,12 @@ | ||
import React from 'react' | ||
import loadable from 'loadable-components' | ||
|
||
const AsyncCounter = loadable(() => import('./Counter')) | ||
|
||
const HotReloadingSandbox = () => ( | ||
<React.Fragment> | ||
Counter: <AsyncCounter /> | ||
</React.Fragment> | ||
) | ||
|
||
export default HotReloadingSandbox |
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 @@ | ||
export default () => 'Amazing' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default () => 'World' |
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,12 @@ | ||
import React from 'react' | ||
import loadable from 'loadable-components' | ||
|
||
const AsyncWorld = loadable(() => import('./World')) | ||
|
||
const AmazingWorld = () => ( | ||
<React.Fragment> | ||
Amazing <AsyncWorld /> | ||
</React.Fragment> | ||
) | ||
|
||
export default AmazingWorld |
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,12 @@ | ||
import React from 'react' | ||
import loadable from 'loadable-components' | ||
|
||
const AsyncAmazingWorld = loadable(() => import('./AmazingWorld')) | ||
|
||
const Nesting = () => ( | ||
<React.Fragment> | ||
This is an <AsyncAmazingWorld /> | ||
</React.Fragment> | ||
) | ||
|
||
export default Nesting |
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 @@ | ||
const World = () => 'World' | ||
|
||
export default World |
File renamed without changes.
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
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react' | ||
import A from './A' | ||
import B from './B' | ||
|
||
const Nesting = () => ( | ||
<React.Fragment> | ||
<A /> <B /> | ||
</React.Fragment> | ||
) | ||
|
||
export default Nesting |
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,33 @@ | ||
import React from 'react' | ||
import ReactDOMServer from 'react-dom/server' | ||
import { StaticRouter } from 'react-router-dom' | ||
import express from 'express' | ||
import { getLoadableState } from 'loadable-components/server' | ||
import App from './App' | ||
|
||
const app = express() | ||
|
||
app.use(async (req, res) => { | ||
try { | ||
const routerContext = {} | ||
const reactApp = ( | ||
<StaticRouter context={routerContext} location={req.url}> | ||
<App /> | ||
</StaticRouter> | ||
) | ||
const loadableState = await getLoadableState(reactApp) | ||
const stream = ReactDOMServer.renderToNodeStream(reactApp) | ||
res.write(`<!DOCTYPE html><html><body><div id="root">`) | ||
stream.pipe(res, { end: false }) | ||
stream.on('end', () => { | ||
res.end( | ||
`</div>${loadableState.getScriptTag()}<script src="bundle.js"></script></body></html>`, | ||
) | ||
}) | ||
} catch (err) { | ||
res.status(500) | ||
res.send(err.stack) | ||
} | ||
}) | ||
|
||
app.listen(3000, () => console.log('http://localhost:3000')) |
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
Oops, something went wrong.