Skip to content

Commit

Permalink
feat(blog): fixing re-render and nesting on hightlight component, als…
Browse files Browse the repository at this point in the history
…o added throttle to the main scroll listener
  • Loading branch information
juancabrera authored and phil-linnell committed Aug 9, 2017
1 parent 4340b23 commit a7bf5c5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/app/components/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React from 'react';
import Meta from "react-helmet";
import TransitionManager from 'react-transition-manager';
import classnames from 'classnames';
import { get } from 'lodash';
import { get, throttle } from 'lodash';
import find from 'lodash/collection/find';
import includes from 'lodash/collection/includes';
import Flux from 'app/flux';
Expand Down Expand Up @@ -91,7 +91,7 @@ const App = React.createClass({
this.getViewportDimensions();

/* Get dimensions of viewport to calculate mousePosition and scrollPosition (for example) */
window.addEventListener('scroll', this.getDocumentScrollPosition);
window.addEventListener('scroll', throttle(() => this.getDocumentScrollPosition(), 240));
/* Get new dimensions when device orientationchange etc */
window.addEventListener('resize', this.getViewportDimensions);

Expand Down
3 changes: 3 additions & 0 deletions src/app/components/post/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import ScrollWrapper from 'app/components/scroll-wrapper';

const PagePost = React.createClass({
mixins: [getScrollTrackerMixin('post')],
shouldComponentUpdate(nextProps, nextState) {
return !this.props.loaded;
},
render() {
const { post, footer, studios, currentPage, documentScrollPosition, viewportDimensions } = this.props;
const category = get(post, '_embedded.wp:term.0.0', []);
Expand Down
5 changes: 1 addition & 4 deletions src/app/lib/module-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,7 @@ function renderVideo(moduleData, index, options) {
}

function renderCode(moduleData, index, options) {
var code = get(moduleData, 'attr.body.value').replace(/(?:\r\n|\r|\n)/g, '<br/>').replace(/ /g, '&nbsp;').replace('Button', ' Button ');
return (
<code className="hljs pf" dangerouslySetInnerHTML={{ __html: code }}></code>
);
return <CodeHighlighter code={get(moduleData, 'attr.body.value')} key={`logitem-${index}-${Date.now()}`} />
}

function renderModules(options) {
Expand Down

0 comments on commit a7bf5c5

Please sign in to comment.