Skip to content

Instantly share code, notes, and snippets.

@david-martin
Created February 14, 2017 12:46
Show Gist options
  • Save david-martin/2cf7be408724660f2e2d9a71718ad37a to your computer and use it in GitHub Desktop.
Save david-martin/2cf7be408724660f2e2d9a71718ad37a to your computer and use it in GitHub Desktop.
for (i in serverRecs) {
var serverRec = serverRecs[i];
var serverRecUid = i;
var serverRecHash = serverRec.hash;
if (clientRecs[serverRecUid]) {
// only do this if there isn't an applied or pending update of this record
if (clientRecs[serverRecUid] !== serverRecHash) {
syncUtil.doLog(dataset_id, 'verbose', 'Updating client record ' + serverRecUid + ' client hash=' + clientRecs[serverRecUid], params);
updates[serverRecUid] = serverRec;
}
} else {
// only do this if there isn't an applied or pending delete of this record
syncUtil.doLog(dataset_id, 'verbose', 'Creating client record ' + serverRecUid, params);
creates[serverRecUid] = serverRec;
}
}
// Itterate over each of the client records. If there is no corresponding server record then mark the client
// record for deletion
for (i in clientRecs) {
if (!serverRecs[i]) {
// only do this if there isn't an applied or pending create of this record
syncUtil.doLog(dataset_id, 'verbose', 'Deleting client record ' + serverRecs[i], params);
deletes[i] = {};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment