p5.js-web-editor/client/utils/previewEntry.js
2018-11-15 17:28:43 -05:00

19 lines
407 B
JavaScript

import loopProtect from 'loop-protect';
import { Hook } from 'console-feed';
window.loopProtect = loopProtect;
const consoleBuffer = [];
const LOGWAIT = 500;
Hook(window.console, (log) => {
consoleBuffer.push({
log,
source: 'sketch'
});
});
setInterval(() => {
if (consoleBuffer.length > 0) {
window.parent.postMessage(consoleBuffer, '*');
consoleBuffer.length = 0;
}
}, LOGWAIT);