Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
65 changed files
with
8,050 additions
and
0 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 |
---|---|---|
|
@@ -6,3 +6,4 @@ lerna-debug.log | |
|
||
packages/*/dist | ||
.changelog | ||
.DS_Store |
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 @@ | ||
yarn.lock |
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,21 @@ | ||
# See https://help.github.com/ignore-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
Large diffs are not rendered by default.
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,20 @@ | ||
{ | ||
"name": "react-router5-new-context-api", | ||
"description": "", | ||
"homepage": "https://stackblitz.com/edit/react-router5-new-context-api", | ||
"dependencies": { | ||
"react": "16.4.2", | ||
"react-dom": "16.4.2", | ||
"react-scripts": "1.1.4", | ||
"router5": "6.4.2", | ||
"react-router5": "6.3.0" | ||
}, | ||
"version": "0.1.0", | ||
"private": true, | ||
"scripts": { | ||
"start": "react-scripts start", | ||
"build": "react-scripts build", | ||
"test": "react-scripts test --env=jsdom", | ||
"eject": "react-scripts eject" | ||
} | ||
} |
Binary file not shown.
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,41 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
<meta name="theme-color" content="#000000"> | ||
<!-- | ||
manifest.json provides metadata used when your web app is added to the | ||
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/ | ||
--> | ||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json"> | ||
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico"> | ||
<!-- | ||
Notice the use of %PUBLIC_URL% in the tags above. | ||
It will be replaced with the URL of the `public` folder during the build. | ||
Only files inside the `public` folder can be referenced from the HTML. | ||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will | ||
work correctly both with client-side routing and a non-root public URL. | ||
Learn how to configure a non-root public URL by running `npm run build`. | ||
--> | ||
|
||
<title>react-router5-new-context-api</title> | ||
</head> | ||
<body> | ||
<noscript> | ||
You need to enable JavaScript to run this app. | ||
</noscript> | ||
<div id="root"></div> | ||
<!-- | ||
This HTML file is a template. | ||
If you open it directly in the browser, you will see an empty page. | ||
You can add webfonts, meta tags, or analytics to this file. | ||
The build step will place the bundled scripts into the <body> tag. | ||
To begin the development, run `npm start` or `yarn start`. | ||
To create a production bundle, use `npm run build` or `yarn build`. | ||
--> | ||
</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,15 @@ | ||
{ | ||
"short_name": "React App", | ||
"name": "Create React App Sample", | ||
"icons": [ | ||
{ | ||
"src": "favicon.ico", | ||
"sizes": "192x192", | ||
"type": "image/png" | ||
} | ||
], | ||
"start_url": "./index.html", | ||
"display": "standalone", | ||
"theme_color": "#000000", | ||
"background_color": "#ffffff" | ||
} |
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,17 @@ | ||
import React from 'react' | ||
import Nav from './Nav' | ||
import Main from './Main' | ||
|
||
export default function App({ emails }) { | ||
return ( | ||
<div className="mail-client"> | ||
<aside> | ||
<Nav /> | ||
</aside> | ||
|
||
<main> | ||
<Main emails={emails} /> | ||
</main> | ||
</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,41 @@ | ||
import React, { Component } from 'react' | ||
import { routeNode } from 'react-router5' | ||
|
||
export default class Compose extends Component { | ||
constructor(props, context) { | ||
super(props, context) | ||
this.state = { | ||
title: '', | ||
message: '' | ||
} | ||
this.updateTitle = this.updateTitle.bind(this) | ||
this.updateMessage = this.updateMessage.bind(this) | ||
} | ||
|
||
updateTitle(evt) { | ||
this.setState({ title: evt.target.value, warning: false }) | ||
} | ||
|
||
updateMessage(evt) { | ||
this.setState({ message: evt.target.value, warning: false }) | ||
} | ||
|
||
render() { | ||
const { title, message, warning } = this.state | ||
|
||
return ( | ||
<div className="compose"> | ||
<h4>Compose a new message</h4> | ||
|
||
<input name="title" value={title} onChange={this.updateTitle} /> | ||
<textarea | ||
name="message" | ||
value={message} | ||
onChange={this.updateMessage} | ||
/> | ||
|
||
{warning ? <p>Clear inputs before continuing</p> : null} | ||
</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,23 @@ | ||
import React from 'react' | ||
import InboxList from './InboxList' | ||
import Message from './Message' | ||
import { RouteNode } from 'react-router5' | ||
|
||
function Inbox(props) { | ||
const { route, emails } = props | ||
|
||
return ( | ||
<div className="inbox"> | ||
<InboxList emails={emails} /> | ||
{route.name === 'inbox.message' ? ( | ||
<Message {...emails[route.params.id]} key={route.params.id} /> | ||
) : null} | ||
</div> | ||
) | ||
} | ||
|
||
export default (props) => ( | ||
<RouteNode nodeName="inbox"> | ||
{({ route }) => <Inbox route={route} {...props} />} | ||
</RouteNode> | ||
) |
19 changes: 19 additions & 0 deletions
19
examples/react-new-context-api/src/components/InboxItem.js
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,19 @@ | ||
import React, { Component } from 'react' | ||
import { Link } from 'react-router5' | ||
|
||
function InboxItem({ title, message, id }) { | ||
return ( | ||
<li> | ||
<Link | ||
routeName="inbox.message" | ||
routeParams={{id }} | ||
activeClassName="active" | ||
> | ||
<h4>{title}</h4> | ||
<p>{message}</p> | ||
</Link> | ||
</li> | ||
) | ||
} | ||
|
||
export default InboxItem |
12 changes: 12 additions & 0 deletions
12
examples/react-new-context-api/src/components/InboxList.js
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 InboxItem from './InboxItem' | ||
|
||
export default function InboxList({ | ||
emails | ||
}) { | ||
return ( | ||
<ul className="mail-list"> | ||
{Object.values(emails).map(mail => <InboxItem {...mail} key={mail.id} />)} | ||
</ul> | ||
) | ||
} |
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,25 @@ | ||
import React from 'react' | ||
import { RouteNode } from 'react-router5' | ||
import Inbox from './Inbox' | ||
import Compose from './Compose' | ||
import NotFound from './NotFound' | ||
|
||
function Main({ route, emails }) { | ||
const topRouteName = route.name.split('.')[0] | ||
|
||
if (topRouteName === 'inbox') { | ||
return <Inbox emails={emails} /> | ||
} | ||
|
||
if (topRouteName === 'compose') { | ||
return <Compose /> | ||
} | ||
|
||
return <NotFound /> | ||
} | ||
|
||
export default (props) => ( | ||
<RouteNode nodeName=""> | ||
{({ route }) => <Main route={route} {...props} />} | ||
</RouteNode> | ||
) |
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' | ||
|
||
export default function Message(props) { | ||
const { title, message } = props | ||
|
||
return ( | ||
<section className="mail"> | ||
<h4>{title}</h4> | ||
<p>{message}</p> | ||
</section> | ||
) | ||
} |
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,26 @@ | ||
import React from 'react' | ||
import { BaseLink, Route } from 'react-router5' | ||
|
||
function Nav(props) { | ||
const { router } = props | ||
|
||
return ( | ||
<nav> | ||
<BaseLink | ||
router={router} | ||
routeName="inbox" | ||
routeOptions={{ reload: true }} | ||
> | ||
Inbox | ||
</BaseLink> | ||
<BaseLink router={router} routeName="compose"> | ||
Compose | ||
</BaseLink> | ||
<BaseLink router={router} routeName="contacts"> | ||
Contacts | ||
</BaseLink> | ||
</nav> | ||
) | ||
} | ||
|
||
export default () => <Route>{({ router }) => <Nav router={router} />}</Route> |
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,5 @@ | ||
import React from 'react' | ||
|
||
export default function NotFound(props) { | ||
return <div className="not-found">Purposely Not found (not a bug)</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,19 @@ | ||
import createRouter from 'router5' | ||
import loggerPlugin from 'router5/plugins/logger' | ||
import browserPlugin from 'router5/plugins/browser' | ||
import routes from './routes' | ||
|
||
export default function configureRouter() { | ||
const router = createRouter(routes, { | ||
defaultRoute: 'inbox' | ||
}) | ||
// Plugins | ||
.usePlugin(loggerPlugin) | ||
.usePlugin( | ||
browserPlugin({ | ||
useHash: true | ||
}) | ||
) | ||
|
||
return router | ||
} |
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,22 @@ | ||
const emails = { | ||
'1': { | ||
id: '1', | ||
title: 'Why router5?', | ||
message: | ||
'I imagine a lot of developers who will first see router5 will ask themselves the question: is it yet another router? is it any good? Why oh why do people keep writing new routers all the time? It is not always easy to see the potential of something straight away, or understand the motivations behind. I therefore decided to try to tell you more about router5, why I decided to develop an entire new routing solution, and what problems it tries to solve.' | ||
}, | ||
'2': { | ||
id: '2', | ||
title: 'Use with React', | ||
message: | ||
'I have just started playing with it. It does make sense to use a flux-like implementation, to provide a layer between the router and view updates.' | ||
}, | ||
'3': { | ||
id: '3', | ||
title: 'Compose a new message', | ||
message: | ||
'Click on compose, start to fill title and message fields and then try to navigate away by clicking on app links, or by using the back button.' | ||
} | ||
} | ||
|
||
export default emails |
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,17 @@ | ||
import ReactDOM from 'react-dom' | ||
import React from 'react' | ||
import App from './components/App' | ||
import { RouteProvider } from 'react-router5' | ||
import createRouter from './create-router' | ||
import emails from './data' | ||
import './style.css' | ||
|
||
const router = createRouter() | ||
|
||
router.start(() => { | ||
ReactDOM.render(( | ||
<RouteProvider router={router}> | ||
<App emails={emails} /> | ||
</RouteProvider> | ||
), document.getElementById('root')) | ||
}) |
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,6 @@ | ||
export default [ | ||
{ name: 'inbox', path: '/inbox' }, | ||
{ name: 'inbox.message', path: '/message/:id' }, | ||
{ name: 'compose', path: '/compose' }, | ||
{ name: 'contacts', path: '/contacts' } | ||
] |
Oops, something went wrong.