Consolidate rendering to helper function

This commit is contained in:
Ray Schamp 2015-10-13 11:45:23 -06:00
parent da9174c520
commit 07be335a42
6 changed files with 24 additions and 33 deletions

13
src/lib/renderer.jsx Normal file
View file

@ -0,0 +1,13 @@
var React = require('react');
var Renderer = {
render: function (jsx, toElement) {
var rendered = React.render(jsx, toElement);
if (process.env.NODE_ENV != 'production') {
window.renderedComponents = window.renderedComponents || [];
window.renderedComponents.push(rendered);
}
}
};
module.exports = Renderer;

View file

@ -1,15 +1,9 @@
var React = require('react');
var Renderer = require('./lib/renderer.jsx');
require('./main.scss');
var Navigation = require('./components/navigation/navigation.jsx');
var Footer = require('./components/footer/footer.jsx');
var renderedNavigation = React.render(<Navigation />, document.getElementById('navigation'));
var renderedFooter = React.render(<Footer />, document.getElementById('footer'));
if (process.env.NODE_ENV != 'production') {
window.renderedComponents = window.renderedComponents || [];
window.renderedComponents.push(renderedNavigation);
window.renderedComponents.push(renderedFooter);
}
Renderer.render(<Navigation />, document.getElementById('navigation'));
Renderer.render(<Footer />, document.getElementById('footer'));

View file

@ -1,4 +1,5 @@
var React = require('react');
var Renderer = require('../../lib/renderer.jsx');
require('./about.scss');
@ -13,9 +14,4 @@ var About = React.createClass({
}
});
var renderedView = React.render(<About />, document.getElementById('view'));
if (process.env.NODE_ENV != 'production') {
window.renderedComponents = window.renderedComponents || [];
window.renderedComponents.push(renderedView);
}
Renderer.render(<About />, document.getElementById('view'));

View file

@ -1,4 +1,5 @@
var React = require('react');
var Renderer = require('../../lib/renderer.jsx');
var Box = require('../../components/box/box.jsx');
var Button = require('../../components/forms/button.jsx');
@ -36,9 +37,4 @@ var Components = React.createClass({
}
});
var renderedView = React.render(<Components />, document.getElementById('view'));
if (process.env.NODE_ENV != 'production') {
window.renderedComponents = window.renderedComponents || [];
window.renderedComponents.push(renderedView);
}
Renderer.render(<Components />, document.getElementById('view'));

View file

@ -1,4 +1,5 @@
var React = require('react');
var Renderer = require('../../lib/renderer.jsx');
require('./hoc.scss');
@ -104,9 +105,4 @@ var Hoc = React.createClass({
}
});
var renderedView = React.render(<Hoc />, document.getElementById('view'));
if (process.env.NODE_ENV != 'production') {
window.renderedComponents = window.renderedComponents || [];
window.renderedComponents.push(renderedView);
}
Renderer.render(<Hoc />, document.getElementById('view'));

View file

@ -1,4 +1,5 @@
var React = require('react');
var Renderer = require('../../lib/renderer.jsx');
var Api = require('../../mixins/api.jsx');
var Session = require('../../mixins/session.jsx');
@ -72,9 +73,4 @@ var Splash = React.createClass({
}
});
var renderedView = React.render(<Splash />, document.getElementById('view'));
if (process.env.NODE_ENV != 'production') {
window.renderedComponents = window.renderedComponents || [];
window.renderedComponents.push(renderedView);
}
Renderer.render(<Splash />, document.getElementById('view'));