diff --git a/client/modules/IDE/components/Console.js b/client/modules/IDE/components/Console.js index 52b33d58..177f53cc 100644 --- a/client/modules/IDE/components/Console.js +++ b/client/modules/IDE/components/Console.js @@ -25,7 +25,7 @@ class Console extends React.Component { componentWillReceiveProps(nextProps) { if (nextProps.isPlaying && !this.props.isPlaying) { this.children = []; - } else if (nextProps.consoleEvent !== this.props.consoleEvent) { + } else if (nextProps.isExpanded && nextProps.consoleEvent !== this.props.consoleEvent) { const args = nextProps.consoleEvent.arguments; const method = nextProps.consoleEvent.method; const nextChild = ( diff --git a/client/modules/IDE/components/PreviewFrame.js b/client/modules/IDE/components/PreviewFrame.js index a45821b0..68c27b8b 100644 --- a/client/modules/IDE/components/PreviewFrame.js +++ b/client/modules/IDE/components/PreviewFrame.js @@ -40,8 +40,29 @@ function hijackConsoleLogsScript() { 'debug', 'clear', 'error', 'info', 'log', 'warn' ]; + + function throttle(fn, threshhold, scope) { + var last, deferTimer; + return function() { + var context = scope || this; + var now = +new Date, + args = arguments; + if (last && now < last + threshhold) { + // hold on to it + clearTimeout(deferTimer); + deferTimer = setTimeout(function() { + last = now; + fn.apply(context, args); + }, threshhold); + } else { + last = now; + fn.apply(context, args); + } + }; + } + methods.forEach( function(method) { - iframeWindow.console[method] = function() { + iframeWindow.console[method] = throttle(function() { originalConsole[method].apply(originalConsole, arguments); var args = Array.from(arguments); @@ -56,11 +77,12 @@ function hijackConsoleLogsScript() { arguments: args, source: 'sketch' }, '*'); - }; + }, 100); }); `; return s; } + function hijackConsoleErrorsScript(offs) { const s = `