diff --git a/site/theme/template/Color/Palette.jsx b/site/theme/template/Color/Palette.jsx
index 6db0f294b1..8bf6a8390b 100644
--- a/site/theme/template/Color/Palette.jsx
+++ b/site/theme/template/Color/Palette.jsx
@@ -26,10 +26,10 @@ export default class Palette extends React.Component {
});
this.forceUpdate();
}
+
render() {
this.colorNodes = this.colorNodes || {};
- const { showTitle, direction } = this.props;
- const { name, description, english, chinese } = this.props.color;
+ const { showTitle, direction, color: { name, description, english, chinese } } = this.props;
const className = direction === 'horizontal' ? 'color-palette-horizontal' : 'color-palette';
const colors = [];
const colorName = `${english} / ${chinese}`;
diff --git a/site/theme/template/Content/Article.jsx b/site/theme/template/Content/Article.jsx
index 02b7e65dd5..80b19fe4e9 100644
--- a/site/theme/template/Content/Article.jsx
+++ b/site/theme/template/Content/Article.jsx
@@ -12,6 +12,7 @@ export default class Article extends React.Component {
static contextTypes = {
intl: PropTypes.object.isRequired,
}
+
componentDidMount() {
// Add ga event click
this.delegation = delegate(this.node, '.resource-card', 'click', (e) => {
@@ -21,6 +22,7 @@ export default class Article extends React.Component {
}, false);
this.componentDidUpdate();
}
+
componentDidUpdate() {
const links = [...document.querySelectorAll('.outside-link.internal')];
if (links.length === 0) {
@@ -34,12 +36,14 @@ export default class Article extends React.Component {
}
});
}
+
componentWillUnmount() {
clearTimeout(this.pingTimer);
if (this.delegation) {
this.delegation.destroy();
}
}
+
getArticle(article) {
const { content } = this.props;
const { meta } = content;
@@ -64,13 +68,13 @@ export default class Article extends React.Component {
children:
{timelineItems},
});
}
+
render() {
const { props } = this;
const { content } = props;
-
const { meta, description } = content;
const { title, subtitle, filename } = meta;
- const { locale } = this.context.intl;
+ const { intl: { locale } } = this.context;
const isNotTranslated = locale === 'en-US' && typeof title === 'object';
return (
@@ -89,26 +93,29 @@ export default class Article extends React.Component {
{title[locale] || title}
{
- !subtitle || locale === 'en-US' ? null :
- {subtitle}
+ !subtitle || locale === 'en-US'
+ ? null
+ : {subtitle}
}
} filename={filename} />
{
- !description ? null :
- props.utils.toReactComponent(
+ !description
+ ? null
+ : props.utils.toReactComponent(
['section', { className: 'markdown' }].concat(getChildren(description))
)
}
{
- (!content.toc || content.toc.length <= 1 || meta.toc === false) ? null :
-
- {
- props.utils.toReactComponent(
- ['ul', { className: 'toc' }].concat(getChildren(content.toc))
- )
- }
-
+ (!content.toc || content.toc.length <= 1 || meta.toc === false) ? null : (
+
+ {
+ props.utils.toReactComponent(
+ ['ul', { className: 'toc' }].concat(getChildren(content.toc))
+ )
+ }
+
+ )
}
{
this.getArticle(props.utils.toReactComponent(
diff --git a/site/theme/template/Content/ComponentDoc.jsx b/site/theme/template/Content/ComponentDoc.jsx
index 963cbec2bb..ecd90d5241 100644
--- a/site/theme/template/Content/ComponentDoc.jsx
+++ b/site/theme/template/Content/ComponentDoc.jsx
@@ -22,8 +22,9 @@ export default class ComponentDoc extends React.Component {
}
handleExpandToggle = () => {
+ const { expandAll } = this.state;
this.setState({
- expandAll: !this.state.expandAll,
+ expandAll: !expandAll,
});
}
@@ -31,15 +32,15 @@ export default class ComponentDoc extends React.Component {
const { props } = this;
const { doc, location } = props;
const { content, meta } = doc;
- const { locale } = this.context.intl;
+ const { intl: { locale } } = this.context;
const demos = Object.keys(props.demos).map(key => props.demos[key]);
- const expand = this.state.expandAll;
+ const { expandAll: { expand } } = this.state;
const isSingleCol = meta.cols === 1;
const leftChildren = [];
const rightChildren = [];
- const showedDemo = demos.some(demo => demo.meta.only) ?
- demos.filter(demo => demo.meta.only) : demos.filter(demo => demo.preview);
+ const showedDemo = demos.some(demo => demo.meta.only)
+ ? demos.filter(demo => demo.meta.only) : demos.filter(demo => demo.preview);
showedDemo.sort((a, b) => a.meta.order - b.meta.order)
.forEach((demoData, index) => {
const demoElem = (
@@ -109,9 +110,10 @@ export default class ComponentDoc extends React.Component {
{leftChildren}
diff --git a/site/theme/template/Content/Demo.jsx b/site/theme/template/Content/Demo.jsx
index 410dc5a534..e34b57e586 100644
--- a/site/theme/template/Content/Demo.jsx
+++ b/site/theme/template/Content/Demo.jsx
@@ -43,9 +43,11 @@ export default class Demo extends React.Component {
}
shouldComponentUpdate(nextProps, nextState) {
- return (this.state.codeExpand || this.props.expand) !== (nextState.codeExpand || nextProps.expand)
- || this.state.copied !== nextState.copied
- || this.state.copyTooltipVisible !== nextState.copyTooltipVisible;
+ const { codeExpand, copied, copyTooltipVisible } = this.state;
+ const { expand } = this.props;
+ return (codeExpand || expand) !== (nextState.codeExpand || nextProps.expand)
+ || copied !== nextState.copied
+ || copyTooltipVisible !== nextState.copyTooltipVisible;
}
componentDidMount() {
@@ -65,7 +67,8 @@ export default class Demo extends React.Component {
}
handleCodeExpand = () => {
- this.setState({ codeExpand: !this.state.codeExpand });
+ const { codeExpand } = this.state;
+ this.setState({ codeExpand: !codeExpand });
}
saveAnchor = (anchor) => {
@@ -102,6 +105,7 @@ export default class Demo extends React.Component {
highlightedStyle,
expand,
} = props;
+ const { showRiddleButton, copied } = state;
if (!this.liveDemo) {
this.liveDemo = meta.iframe
?
@@ -112,8 +116,7 @@ export default class Demo extends React.Component {
'code-box': true,
expand: codeExpand,
});
-
- const { locale } = this.context.intl;
+ const { intl: { locale } } = this.context;
const localizedTitle = meta.title[locale] || meta.title;
const localizeIntro = content[locale] || content;
const introChildren = props.utils
@@ -186,9 +189,9 @@ ${state.sourceCode.replace('mountNode', 'document.getElementById(\'container\')'
{this.liveDemo}
{
- style ?
- :
- null
+ style
+ ?
+ : null
}
@@ -222,7 +225,7 @@ ${state.sourceCode.replace('mountNode', 'document.getElementById(\'container\')'
>
- {this.state.showRiddleButton ? (
+ {showRiddleButton ? (