Skip to content

Commit eba9ebe

Browse files
authored
Merge v3-beta into master (#2809)
* Add examples/with-redux-code-splitting. (#2721) * #1757 Relay Modern Example (#2696) * Add ReasonML example (#2640) * Add ReasonML example * Add a gitignore specifically for the reasonml example * Allow custom className for <Main /> (#2802) * 3.0.2 * Remove beta information from the README. * 3.0.3 * Remove unnecessary lookup in example with emotion (#2731) * Document SCSS/Less (#2742) * Document SCSS/Less * Add missing word * Add docs for examples dir * Add extra example * uppercase J * Add with pkg example (#2751) * Add custom server micro example (#2750) * Ease running multiple examples at the same time with process.env.PORT (#2753) * Add line-height rule for error page h2 (#2761) * Add support for fetching multiple translation files (#2743) * Add support for fetching multiple translation files * Cleanup * Clear missed interval (#2611) * clear missed interval * remove trailing whitespace * Relay Modern Example (#1757) (#2773) * Simplification of Relay Modern Example (#1757) (#2776) * Use deterministic names for dynamic import (#2788) * Always use the same name for the same dynamic import. * Add unit tests for the modulePath generation. * Allow tests to run correctly on Windows. * Make the chunk name a bit pretty. * Fix tests to run on Windows. * 3.0.4 * Revert "Make the chunk name a bit pretty." (#2792) This reverts commit 0c9e8cf. * 3.0.5 * Use _ as the divider for dynamic import name splitter. (#2793) Using - gives us some weird webpack errors. * 3.0.6 * next/dynamic Error Message Tweaks (#2798) * Fixed issue (#2804) #2800 * docs(material-ui): move the source code to Material-UI repository (#2808)
1 parent b543795 commit eba9ebe

File tree

26 files changed

+408
-3
lines changed

26 files changed

+408
-3
lines changed

examples/with-reasonml/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bs
2+
.merlin

examples/with-reasonml/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-reasonml)
2+
# Example app using ReasonML & ReasonReact components
3+
4+
## How to use
5+
6+
Download the example [or clone the repo](https://github.com/zeit/next.js):
7+
8+
```bash
9+
curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/with-reasonml
10+
cd with-reasonml
11+
```
12+
13+
Install it and run:
14+
15+
```bash
16+
npm install
17+
npm run dev
18+
```
19+
20+
Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))
21+
22+
```bash
23+
now
24+
```
25+
26+
## The idea behind the example
27+
28+
This example features:
29+
30+
* An app that mixes together JavaScript and ReasonML components and functions
31+
* An app with two pages which has a common Counter component
32+
* That Counter component maintain the counter inside its module. This is used primarily to illustrate that modules get initialized once and their state variables persist in runtime

examples/with-reasonml/bsconfig.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "with-reasonml",
3+
"sources": ["components", "pages"],
4+
"bs-dependencies": ["reason-react"],
5+
"reason": { "react-jsx": 2 },
6+
"package-specs": ["commonjs"]
7+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
let component = ReasonReact.statefulComponent "Counter";
2+
let make _children => {
3+
...component,
4+
initialState: fun () => 0,
5+
render: fun self => {
6+
let countMsg = "Count: " ^ (string_of_int self.state);
7+
let onClick _evt {ReasonReact.state} => ReasonReact.Update (state + 1);
8+
9+
<div>
10+
<p> (ReasonReact.stringToElement countMsg) </p>
11+
<button onClick=(self.update onClick)> (ReasonReact.stringToElement "Add") </button>
12+
</div>
13+
}
14+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
let component = ReasonReact.statelessComponent "Header";
2+
let styles = ReactDOMRe.Style.make
3+
marginRight::"10px"
4+
();
5+
let make _children => {
6+
...component,
7+
render: fun _self => {
8+
<div>
9+
<a href="/" style=styles> (ReasonReact.stringToElement "Home") </a>
10+
<a href="/about" style=styles> (ReasonReact.stringToElement "About") </a>
11+
</div>
12+
}
13+
};

examples/with-reasonml/index.js

Whitespace-only changes.

examples/with-reasonml/lib/js/components/counter.js

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/with-reasonml/lib/js/components/header.js

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/with-reasonml/lib/js/components/link.js

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/with-reasonml/lib/js/pages/about.js

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/with-reasonml/lib/js/pages/index.js

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/with-reasonml/package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "with-reasonml",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"dev": "next -w",
6+
"build": "next build",
7+
"start": "next start -w"
8+
},
9+
"license": "ISC",
10+
"dependencies": {
11+
"babel-plugin-bucklescript": "^0.2.3-1",
12+
"bs-platform": "^1.8.1",
13+
"next": "^2.4.7",
14+
"react": "^15.6.1",
15+
"react-dom": "^15.6.1",
16+
"reason-react": "^0.2.3"
17+
},
18+
"babel": {
19+
"presets": [
20+
"next/babel"
21+
],
22+
"plugins": [
23+
"babel-plugin-bucklescript"
24+
]
25+
}
26+
}

examples/with-reasonml/pages/About.re

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
let component = ReasonReact.statelessComponent "About";
2+
let make _children => {
3+
...component,
4+
render: fun _self => {
5+
<div>
6+
<Header />
7+
<p>(ReasonReact.stringToElement "This is the about page.")</p>
8+
<Counter />
9+
</div>
10+
}
11+
};
12+
let jsComponent =
13+
ReasonReact.wrapReasonForJs
14+
::component
15+
(fun _jsProps => make [||])

examples/with-reasonml/pages/Index.re

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
let component = ReasonReact.statelessComponent "Index";
2+
let make _children => {
3+
...component,
4+
render: fun _self => {
5+
<div>
6+
<Header />
7+
<p>(ReasonReact.stringToElement "HOME PAGE is here!")</p>
8+
<Counter />
9+
</div>
10+
}
11+
};
12+
let jsComponent =
13+
ReasonReact.wrapReasonForJs
14+
::component
15+
(fun _jsProps => make [||])

examples/with-reasonml/pages/about.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { jsComponent as About } from './about.re'
2+
import React from 'react'
3+
4+
export default () => <About />

examples/with-reasonml/pages/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { jsComponent as Index } from './index.re'
2+
3+
export default () => <Index />
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/with-redux-code-splitting)
3+
4+
# Redux with code splitting example
5+
6+
## How to use
7+
8+
Download the example [or clone the repo](https://github.com/zeit/next.js):
9+
10+
```bash
11+
curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/with-redux-code-splitting
12+
cd with-redux-code-splitting
13+
```
14+
15+
Install it and run:
16+
17+
```bash
18+
npm install
19+
npm run dev
20+
```
21+
22+
Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))
23+
24+
```bash
25+
now
26+
```
27+
28+
## The idea behind the example
29+
30+
Redux uses single store per application and usually it causes problems for code splitting when you want to load actions and reducers used on the current page only.
31+
32+
This example utilizes [fast-redux](https://github.com/dogada/fast-redux) to split Redux's actions and reducers across pages. In result each page's javascript bundle contains only code that is used on the page. When user navigates to a new page, its actions and reducers are connected to the single shared application store.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { createStore, applyMiddleware } from 'redux'
2+
import { composeWithDevTools } from 'redux-devtools-extension'
3+
import thunkMiddleware from 'redux-thunk'
4+
import withRedux from 'next-redux-wrapper'
5+
import { rootReducer } from 'fast-redux'
6+
7+
export const initStore = (initialState = {}) => {
8+
return createStore(rootReducer, initialState,
9+
composeWithDevTools(applyMiddleware(thunkMiddleware)))
10+
}
11+
12+
export const reduxPage = (comp) => withRedux(initStore)(comp)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react'
2+
import {bindActionCreators} from 'redux'
3+
import {connect} from 'react-redux'
4+
import {namespaceConfig} from 'fast-redux'
5+
import Link from 'next/link'
6+
7+
const DEFAULT_STATE = {version: 1}
8+
9+
const {actionCreator, getState: getAboutState} = namespaceConfig('about', DEFAULT_STATE)
10+
11+
const bumpVersion = actionCreator(function bumpVersion (state, increment) {
12+
return {...state, version: state.version + increment}
13+
})
14+
15+
const About = ({ version, bumpVersion }) => (
16+
<div>
17+
<h1>About us</h1>
18+
<h3>Current version: {version}</h3>
19+
<p><button onClick={(e) => bumpVersion(1)}>Bump version!</button></p>
20+
<Link href='/'><a>Homepage</a></Link>
21+
</div>
22+
)
23+
24+
function mapStateToProps (state) {
25+
return getAboutState(state, 'version')
26+
}
27+
28+
function mapDispatchToProps (dispatch) {
29+
return bindActionCreators({ bumpVersion }, dispatch)
30+
}
31+
32+
export default connect(mapStateToProps, mapDispatchToProps)(About)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react'
2+
import {bindActionCreators} from 'redux'
3+
import {connect} from 'react-redux'
4+
import {namespaceConfig} from 'fast-redux'
5+
import Link from 'next/link'
6+
7+
const DEFAULT_STATE = {build: 1}
8+
9+
const {actionCreator, getState: getHomepageState} = namespaceConfig('homepage', DEFAULT_STATE)
10+
11+
const bumpBuild = actionCreator(function bumpBuild (state, increment) {
12+
return {...state, build: state.build + increment}
13+
})
14+
15+
const Homepage = ({ build, bumpBuild }) => (
16+
<div>
17+
<h1>Homepage</h1>
18+
<h3>Current build: {build}</h3>
19+
<p><button onClick={(e) => bumpBuild(1)}>Bump build!</button></p>
20+
<Link href='/about'><a>About Us</a></Link>
21+
</div>
22+
)
23+
24+
function mapStateToProps (state) {
25+
return getHomepageState(state)
26+
}
27+
28+
function mapDispatchToProps (dispatch) {
29+
return bindActionCreators({ bumpBuild }, dispatch)
30+
}
31+
32+
export default connect(mapStateToProps, mapDispatchToProps)(Homepage)

0 commit comments

Comments
 (0)