Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

small javascript code cleanup #138

Merged
merged 2 commits into from
Mar 17, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions lib/sqlite.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,39 +588,42 @@ SQLitePluginTransaction.prototype.run = function() {
}
};
};

i = 0;
mycbmap = {};
mycbmap = [];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why do we need to have an array here

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,
params: request.params
});
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;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I don't understand the reason behind such complexity.
Though I'm not a js developer so I might be missing something.

for (i = j = 0, ref = last; 0 <= ref ? j <= ref : j >= ref; i = 0 <= ref ? ++j : --j) {

the ref could be == -1 only in case the map is empty.
I don't think we need to handle this case there.

In all other cases, the ref is >= 0.
So 0 <= ref is always true and we never will use --j and j >= ref.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reason for this is that it is translated from a coffee script. I keep it in sync with Cordova plugin.

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);
}
}
}
};

var myerror = function(error) {
console.log("batch execution error: ",error);
};
Expand All @@ -630,7 +633,7 @@ SQLitePluginTransaction.prototype.run = function() {
dbname: this.db.dbname
},
executes: tropts
},mysuccess, myerror);
}, mysuccess, myerror);
};

SQLitePluginTransaction.prototype.abort = function(txFailure) {
Expand Down