Created
May 5, 2015 15:57
-
-
Save vslinko/4e781766eed22a0adc65 to your computer and use it in GitHub Desktop.
when you have many root components
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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