p5.js-web-editor/client/utils/previewEntry.js

19 lines
385 B
JavaScript
Raw Normal View History

import loopProtect from 'loop-protect';
2018-08-20 18:54:12 +00:00
import { Hook } from 'console-feed';
window.loopProtect = loopProtect;
const consoleBuffer = [];
const LOGWAIT = 500;
Hook(window.console, (log) => {
consoleBuffer.push({
log
});
});
setInterval(() => {
if (consoleBuffer.length > 0) {
window.parent.postMessage(consoleBuffer, '*');
consoleBuffer.length = 0;
}
}, LOGWAIT);