From 194f3449751b90c1f8d7ec3625ab26594bc808c6 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Mon, 5 Oct 2015 10:11:26 +0200 Subject: Move makeActivityHandler to core.js There were three identical copies for {prolog,python,robot}.js. --- js/codeq/python.js | 47 +---------------------------------------------- 1 file changed, 1 insertion(+), 46 deletions(-) (limited to 'js/codeq/python.js') diff --git a/js/codeq/python.js b/js/codeq/python.js index 214b249..4254d8c 100644 --- a/js/codeq/python.js +++ b/js/codeq/python.js @@ -156,51 +156,6 @@ return terminal; }; - var makeActivityHandler = function (editor, problem_id) { - var lastActivityMillis = Date.now(), - deltaActivityMillis = function deltaActivityMillisFunc () { - var now = Date.now(), - dt = now - lastActivityMillis; - lastActivityMillis = now; - return dt; - }, - queue = [], - ts = null, - timer = function () { - var promise; - ts = null; - if (queue.length === 0) return Q(true); - promise = codeq.comms.sendActivity(queue, editor.getDoc().getValue(), problem_id); - queue.length = 0; - return promise; - }, - flush = function () { - clearTimeout(ts); - return timer(); - }; - - return { - 'queueTrace': function (trace) { - trace['dt'] = deltaActivityMillis(); - queue.push(trace); - if (ts === null) ts = setTimeout(timer, 10000); // flush every 10 seconds - return this; - }, - 'flush': flush, - 'addAndPurge': function (trace) { - var accumulatedTrace = queue; - queue = []; - trace['dt'] = deltaActivityMillis(); - accumulatedTrace.push(trace); - if (ts !== null) { - clearTimeout(ts); - ts = null; - } - return accumulatedTrace; - } - }; - }; - codeq.on('init', function (args) { codeq.tr.registerDictionary('python', codeq.tr.emptyDictionary); // to make the translator happy, when this screen is not active }); @@ -222,7 +177,7 @@ indentUnit: 4, value: currentSolution || '' }), - activityHandler = makeActivityHandler(editor, problemDef.id), + activityHandler = codeq.makeActivityHandler(editor, problemDef.id), terminal = makePythonTerminalHandler(jqTerminal, editor, problemDef.id, activityHandler), hinter = codeq.makeHinter(jqHints, jqEditor, editor, 'python_hints', problemDef, commonDef), commError = function (error) { -- cgit v1.2.1