p5.js-web-editor/client/utils/previewEntry.js
2018-08-20 14:54:12 -04:00

21 lines
472 B
JavaScript

import loopProtect from 'loop-protect';
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);