Skip to content

Instantly share code, notes, and snippets.

@vslinko
Created May 5, 2015 15:57
Show Gist options
  • Save vslinko/4e781766eed22a0adc65 to your computer and use it in GitHub Desktop.
Save vslinko/4e781766eed22a0adc65 to your computer and use it in GitHub Desktop.
when you have many root components
import R from 'ramda';
import React from 'react';
let scheduled = [];
let loaded = false;
document.addEventListener('DOMContentLoaded', () => {
loaded = true;
scheduled.forEach(({flux, Component, selector, props}) => {
render(flux, Component, selector, props);
});
scheduled = [];
});
function render(flux, Component, selector, props) {
const node = document.getElementById(selector);
React.render(<Component flux={flux} {...props} />, node);
}
export default R.curry(function scheduleRender(flux, Component, selector, props) {
if (loaded) {
render(flux, Component, selector, props);
} else {
scheduled.push({flux, Component, selector, props});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment