Skip to content

Commit 60aa586

Browse files
committed
document: refactoring
1 parent 0544c24 commit 60aa586

File tree

1 file changed

+13
-60
lines changed

1 file changed

+13
-60
lines changed

lib/document.js

Lines changed: 13 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,16 @@
1-
import React, { Component, PropTypes } from 'react'
1+
import React from 'react'
22
import htmlescape from 'htmlescape'
33

4-
export default class Document extends Component {
5-
static childContextTypes = {
6-
_documentProps: PropTypes.any
7-
}
8-
9-
getChildContext () {
10-
return {
11-
_documentProps: this.props
12-
}
13-
}
14-
15-
render () {
16-
return <html>
17-
<Head />
18-
<body>
19-
<Main />
20-
<DevTools />
21-
<NextScript />
22-
</body>
23-
</html>
24-
}
25-
}
26-
27-
export function Head (props, context) {
28-
const { head, css } = context._documentProps
29-
const h = (head || [])
30-
.map((h, i) => React.cloneElement(h, { key: '_next' + i }))
31-
return <head>
32-
{h}
33-
<style data-aphrodite='' dangerouslySetInnerHTML={{ __html: css.content }} />
34-
</head>
35-
}
36-
37-
Head.contextTypes = { _documentProps: PropTypes.any }
38-
39-
export function Main (props, context) {
40-
const { html, data, staticMarkup } = context._documentProps
41-
return <div>
42-
<div id='__next' dangerouslySetInnerHTML={{ __html: html }} />
43-
{staticMarkup ? null : <script dangerouslySetInnerHTML={{ __html: '__NEXT_DATA__ = ' + htmlescape(data) }} />}
44-
</div>
4+
export default ({ head, css, html, data, dev, staticMarkup }) => {
5+
return <html>
6+
<head>
7+
{(head || []).map((h, i) => React.cloneElement(h, { key: i }))}
8+
<style data-aphrodite='' dangerouslySetInnerHTML={{ __html: css.content }} />
9+
</head>
10+
<body>
11+
<div id='__next' dangerouslySetInnerHTML={{ __html: html }} />
12+
{staticMarkup ? null : <script dangerouslySetInnerHTML={{ __html: '__NEXT_DATA__ = ' + htmlescape(data) }} />}
13+
{staticMarkup ? null : <script type='text/javascript' src={dev ? '/_next/next-dev.bundle.js' : '/_next/next.bundle.js'} />}
14+
</body>
15+
</html>
4516
}
46-
47-
Main.contextTypes = { _documentProps: PropTypes.any }
48-
49-
export function DevTools (props, context) {
50-
const { hotReload } = context._documentProps
51-
return hotReload ? <div id='__next-hot-code-reloading-indicator' /> : null
52-
}
53-
54-
DevTools.contextTypes = { _documentProps: PropTypes.any }
55-
56-
export function NextScript (props, context) {
57-
const { dev, staticMarkup } = context._documentProps
58-
if (staticMarkup) return null
59-
const src = !dev ? '/_next/next.bundle.js' : '/_next/next-dev.bundle.js'
60-
return <script type='text/javascript' src={src} />
61-
}
62-
63-
NextScript.contextTypes = { _documentProps: PropTypes.any }

0 commit comments

Comments
 (0)