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

22 lines
472 B
JavaScript
Raw Normal View History

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