From d11af7a42bae575b77dbe59015738ad252816da0 Mon Sep 17 00:00:00 2001 From: Sergei Dryganets Date: Tue, 14 Mar 2017 17:13:35 -0700 Subject: [PATCH 1/2] small javascript code cleanup --- lib/sqlite.core.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/sqlite.core.js b/lib/sqlite.core.js index 46d18352..641f4785 100644 --- a/lib/sqlite.core.js +++ b/lib/sqlite.core.js @@ -588,14 +588,15 @@ SQLitePluginTransaction.prototype.run = function() { } }; }; + i = 0; - mycbmap = {}; + mycbmap = []; while (i < batchExecutes.length) { request = batchExecutes[i]; - mycbmap[i] = { + mycbmap.push({ success: handlerFor(i, true), error: handlerFor(i, false) - }; + }); tropts.push({ qid: 1111, sql: request.sql, @@ -603,17 +604,18 @@ SQLitePluginTransaction.prototype.run = function() { }); i++; } + let mysuccess = function(result) { - var j, last, q, r, ref, res, type; + var j, last, q, r, res, type; if (result.length == 0){ return; } last = result.length - 1; - for (i = j = 0, ref = last; 0 <= ref ? j <= ref : j >= ref; i = 0 <= ref ? ++j : --j) { - r = result[i]; + for (j = 0; j <= last; ++j) { + r = result[j]; type = r.type; res = r.result; - q = mycbmap[i]; + q = mycbmap[j]; if (q) { if (q[type]) { q[type](res); @@ -621,6 +623,7 @@ SQLitePluginTransaction.prototype.run = function() { } } }; + var myerror = function(error) { console.log("batch execution error: ",error); }; @@ -630,7 +633,7 @@ SQLitePluginTransaction.prototype.run = function() { dbname: this.db.dbname }, executes: tropts - },mysuccess, myerror); + }, mysuccess, myerror); }; SQLitePluginTransaction.prototype.abort = function(txFailure) { From 46bae5984a603c0176b16d64b58b67c25cb88cd8 Mon Sep 17 00:00:00 2001 From: Sergei Dryganets Date: Tue, 14 Mar 2017 17:46:20 -0700 Subject: [PATCH 2/2] formatting fixes. mycbmap renamed to callbacks. --- lib/sqlite.core.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/sqlite.core.js b/lib/sqlite.core.js index 641f4785..189f684f 100644 --- a/lib/sqlite.core.js +++ b/lib/sqlite.core.js @@ -550,7 +550,7 @@ SQLitePluginTransaction.prototype.handleStatementFailure = function(handler, res }; SQLitePluginTransaction.prototype.run = function() { - var batchExecutes, handlerFor, i, mycbmap, request, tropts, tx, txFailure, waiting; + var batchExecutes, handlerFor, i, callbacks, request, tropts, tx, txFailure, waiting; txFailure = null; tropts = []; batchExecutes = this.executes; @@ -590,10 +590,10 @@ SQLitePluginTransaction.prototype.run = function() { }; i = 0; - mycbmap = []; + callbacks = []; while (i < batchExecutes.length) { request = batchExecutes[i]; - mycbmap.push({ + callbacks.push({ success: handlerFor(i, true), error: handlerFor(i, false) }); @@ -611,11 +611,11 @@ SQLitePluginTransaction.prototype.run = function() { return; } last = result.length - 1; - for (j = 0; j <= last; ++j) { + for (j = 0; j <= last; ++j) { r = result[j]; type = r.type; res = r.result; - q = mycbmap[j]; + q = callbacks[j]; if (q) { if (q[type]) { q[type](res);