Skip to content

Commit

Permalink
fix: do not use memoize & co
Browse files Browse the repository at this point in the history
Why use memoize here @bobylito? Is this some optimization?
  • Loading branch information
vvo committed Aug 1, 2015
1 parent 318547c commit 32c64e6
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions components/templates/Hogan/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
var React = require('react');

var hogan = require('hogan.js');
var memoize = require('lodash/function/memoize');

var memoHogan = memoize(hogan.compile.bind(hogan));

var HoganResult = React.createClass({
propTypes: {
Expand All @@ -14,12 +11,12 @@ var HoganResult = React.createClass({
},
componentWillMount: function() {
this.setState({
template: memoHogan(this.props.template)
template: hogan.compile(this.props.template)
});
},
render: function() {
var content = this.state.template.render(this.props.data);

This comment has been minimized.

Copy link
@bobylito

bobylito Aug 1, 2015

Contributor

We should avoid state here. Indeed because of the internal cache of Hogan, we can simply call for the compilation directly and we will have a pretty consistent low time for compilation + rendering of the template.

var content = hogan.compile(this.props.template).render(this.props.data);

And therefore we can have a pure component, YEAHA!!

This comment has been minimized.

Copy link
@vvo

vvo Aug 1, 2015

Contributor

And therefore we can have a pure component, YEAHA!!

Ok I did the change

return <div dangerouslySetInnerHTML={{__html: content}} />;
return <div className="hit" dangerouslySetInnerHTML={{__html: content}} />;
}
});

Expand Down

0 comments on commit 32c64e6

Please sign in to comment.