-
Notifications
You must be signed in to change notification settings - Fork 109
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
Sync50a #407
base: master
Are you sure you want to change the base?
Sync50a #407
Conversation
@McBen It took (me) hours to understand SYNC as it was hardly commented at all. Yes code is read by programmers, but some are more skilled than others and some "see" the symantics from long constructs like x= a ? b : c; esp if a and b are implemented as functions. when I read code I endorse evrey single bit of comment the programmer added as this will explain his intention and makes debugging way more easy (for me). You may call me a bad programmer, but if we want new DEVs the current uncommented code is tough stuff. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just started to add some comments to the comments :)
Didn't had time for all..that was simply too much.
@@ -35,7 +35,7 @@ window.plugin.sync.authorizer = null; | |||
window.plugin.sync.registeredPluginsFields = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not comment the real important stuff like this?
What is it for? What's the structure of that variable?
registeredMap = new plugin.sync.RegisteredMap(options); // create a new datasructure | ||
// for the calling plugin and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double line comments
some one might (accidently) add a code line between them and split the comment
plugin.sync.registeredPluginsFields.add(registeredMap); | ||
registeredMap = new plugin.sync.RegisteredMap(options); // create a new datasructure | ||
// for the calling plugin and | ||
plugin.sync.registeredPluginsFields.add(registeredMap); // add it to the main structure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as said above. would a explanlation of "sync.registeredPluginFields" wouldn't tell much more ?
}; | ||
|
||
|
||
|
||
//// RegisteredMap | ||
//// RegisteredMap ************************************************************************* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: comments like "*************" usually mean: split this here in 2 files
this.doSync = 'remote'; // normal 'sync' | ||
// 'no' sync needed | ||
// force 'remote' (1st sync) | ||
// force 'local' | ||
// sync is on 'stop' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the comment. I assume "sync","no","remote","local","stop" are valid states of doSync
?
maybe better something like - just my guess what they could mean:
this.doSync = 'remote'; // normal 'sync' | |
// 'no' sync needed | |
// force 'remote' (1st sync) | |
// force 'local' | |
// sync is on 'stop' | |
/** | |
* doSync : state of current sync | |
* = "sync" : normal sync (what ever this means) | |
* = "no" : sync needed (or "no sync running, start delay" ?) | |
* = "stop" : sync stopped by user | |
* = "remote" : get values from remote | |
* = "local : use local values instead of remote | |
*/ | |
this.doSync = 'remote'; |
|
||
this.dataStorage.initialize( // initalize the dataStorage to gain | ||
this.forceFileSearch, // find the related file on drive | ||
assignIdCallback, // onSuccess: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is it named "assignIdCallback" ? it only triggers the callback? isn't it?
}; | ||
|
||
window.plugin.sync.RegisteredMap.prototype.initialize = function(callback) { | ||
this.initFile(this.loadDocument); | ||
}; | ||
|
||
// prepend UUID to data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// prepend UUID to data | |
// prepend UUID to data |
space
); | ||
|
||
this.dataStorage.initialize( // initalize the dataStorage to gain | ||
this.forceFileSearch, // find the related file on drive |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.forceFileSearch, // find the related file on drive | |
this.forceFileSearch, // if true: find the related file on drive |
But the "initialze" function should explain what the parameters are for. Not the function call.
If using a javadoc style comments most IDE's will display this informations.
@@ -162,46 +183,109 @@ window.plugin.sync.RegisteredMap.prototype.loadDocument = function(callback) { | |||
// this function called when the document is created first time | |||
// and the JSON file is populated with data in plugin field | |||
initializeFile = function() { | |||
_this.map = {}; | |||
_this.map = {}; // create an empty map |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_this.map = {}; // create an empty map | |
_this.map = {}; |
$.each(window.plugin[_this.pluginName][_this.fieldName], function(key, val) { | ||
_this.map[key] = val; | ||
}); | ||
|
||
_this.dataStorage.saveFile(_this.prepareFileData()); | ||
_this.dataStorage.saveFile(_this.prepareFileData()); // save the map to drive |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_this.dataStorage.saveFile(_this.prepareFileData()); // save the map to drive | |
_this.dataStorage.saveFile(_this.prepareFileData()); |
In general agree with @McBen. See also https://github.com/IITC-CE/ingress-intel-total-conversion/wiki/Contributing-Code about commit messages style. |
a34b800
to
7b9edd5
Compare
Commenting SYNC is "work in progress" and some comments might even need to be revised.
fixed |
Some comments are required. Some comments might by helpful. But they always cost time to write, read and maintain. They can be boring and in worst case be missleading or wrong. Style
right now you're jumping left & right. This style of comments are fine when teaching someone to code. You've the pure code on the left and the documention on the right. This way you can focus and explain the code without the distraction of comments. While developing this is terrible wrong. While developing code & comments should be a unit. I expect a comment is important, has a valid reason to be there and I've to read it. (like |
Still I prefer that way of explaining the code and if Xelio had done so in 2013 it wouldn't have cost us/me weeks to understand the code and someone else could have taken the job to refurbish it way earlier. Up to now all we received from other DEVs was "SYNC is a mess, I do not understand it, I will not touch it, I use my own code." SYNC is very "difficult" code and digging out the ideas @Xelio had in 2013 is time consuming, but unavoidable if we want to keep SYNC alive and compatible. For the time being the comment style will be "Code-Teaching". When the process is done, we can think about dropping, merging or rewriting comments. |
So may be it's worth some refactoring to make it easier? Better spent time simplifying things than explaining wh things are so complicated. |
@johnd0e I explained my intention, the plan, the future development and that the remarks are valuable and will be taken forward into the next steps. If you do not like my changed comments but still feel the issue is valid you are free to cherry-pick the dev-part only or ignore the PR. |
// this function called when the document is loaded | ||
// update local data if the document is updated by other (overwrite!) | ||
// and adding a timer to further check for updates | ||
// this function gets called when the document is loaded |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'document' usually reference to window.document
. Here we talk about a g-drive file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some more comments
// execute the callback functions | ||
if(_this.callback) _this.callback( // execute the callback functions with | ||
_this.pluginName, // pluginName | ||
_this.fieldName, // fieldName | ||
null, // null (for backwards compatibility) | ||
true // true = full file load from Drive | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// execute the callback functions | |
if(_this.callback) _this.callback( // execute the callback functions with | |
_this.pluginName, // pluginName | |
_this.fieldName, // fieldName | |
null, // null (for backwards compatibility) | |
true // true = full file load from Drive | |
); | |
// execute the callback functions | |
if(_this.callback) _this.callback( | |
_this.pluginName, | |
_this.fieldName, | |
null, // obsolete, for backwards compatibility | |
true // load complete file | |
); |
// Store RegisteredMap and handle initialization of RegisteredMap | ||
window.plugin.sync.RegisteredPluginsFields = function(options) { | ||
this.authorizer = options['authorizer']; | ||
this.authorizer = options['authorizer']; // |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty comment
this.authorizer = options['authorizer']; // | |
this.authorizer = options['authorizer']; |
clearTimeout(this.timer); // reset the timer | ||
if(Object.keys(this.waitingInitialize).length > 0) { // if queue still not empty | ||
this.timer = setTimeout( | ||
function() {_this.initializeWorker()}, 10000 // retry in 10 sec |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move time constant to extra variable
function() {_this.initializeWorker()}, 10000 // retry in 10 sec | |
function() {_this.initializeWorker()}, RETRY_TIME |
NB: also comment in 318 references this
} | ||
}; | ||
//// end RegisteredPluginsFields | ||
|
||
|
||
|
||
|
||
//// DataManager | ||
//// DataManager *************************************************************************** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is a sign for "split this file here"
function () { | ||
gapi.client.request({ | ||
path: '/upload/drive/v3/files/'+_this.fileId, | ||
method: 'PATCH', // why patch? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't ask me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try with PUT
https://developers.google.com/drive/api/v2/reference/files/update
Google is likely to translate PATCH
by PUT
on the route https://www.googleapis.com/upload/drive/v2/files/{fileId}
window.plugin.sync.updateLog = function(messages) { | ||
$('#sync-log').html(messages); | ||
}; | ||
|
||
// AuthButon that shows IN the dialog |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// AuthButon that shows IN the dialog | |
// Toggle the state of the AuthButton in sync dialog |
@@ -717,6 +790,7 @@ window.plugin.sync.toggleAuthButton = function() { | |||
$('#sync-authButton').toggleClass('sync-authButton-dimmed', authed || authorizing); | |||
}; | |||
|
|||
// Sync menuitem in the toolbox |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"toggle" and "sync" sounds really differnt..one of it might be wrong
window.plugin.sync.logger = new plugin.sync.Logger( | ||
{'logLimit':10, 'logUpdateCallback': plugin.sync.updateLog} | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
go the full way
window.plugin.sync.logger = new plugin.sync.Logger( | |
{'logLimit':10, 'logUpdateCallback': plugin.sync.updateLog} | |
); | |
window.plugin.sync.logger = new plugin.sync.Logger({ | |
logLimit: 10, | |
logUpdateCallback: plugin.sync.updateLog | |
}); |
window.plugin.sync.authorizer = new window.plugin.sync.Authorizer({ | ||
'authCallback': [plugin.sync.toggleAuthButton, plugin.sync.toggleDialogLink] | ||
}); | ||
// create an authorizer structure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep the empty line as separator
'authCallback': [plugin.sync.toggleAuthButton, // functions to execute after | ||
plugin.sync.toggleDialogLink // successfull authorization |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another good example why this comment format is bad,
if you add another callback this comment get's messed up ... and it's currently hard to read if you're just looking for "toggleDialogLink"
Comments & linebreaks added to many lines to help understand the code
Commenting the code
Conflict detection implemented.
@MysticJay Do you intend to continue this contribution? If not, could you close it? |
SYNC collision handling
Summary: multiple active clients accessing the drive might cause IITC to "forget" recently done changes when polling the drive.
Added a collision detection that will ask the user with which data-set to continue.
Clean copy of PR #403
addressing Issue #394
Status: RC1