Asynchronously delay JS until a condition is met
You could also achieve this using lodash's debouncer with recursion.
import _debounce from 'lodash/debounce';
const wait = (() => {
if ( chatroom.json ) {
chatroom.render();
} else {
_debounce(wait, 500)();
}
})();
Consider this:
(function wait() {
if ( chatroom.json ) {
chatroom.render();
} else {
setTimeout( wait, 500 );
}
})();
This will check every half second.
Live demo: http://jsfiddle.net/kBgTx/