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

20 lines
407 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,
2018-11-15 22:28:43 +00:00
source: 'sketch'
});
});
setInterval(() => {
if (consoleBuffer.length > 0) {
window.parent.postMessage(consoleBuffer, '*');
consoleBuffer.length = 0;
}
}, LOGWAIT);