Skip to content

Instantly share code, notes, and snippets.

@lholmquist
Last active January 3, 2016 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lholmquist/81de9737b5c91367aa3c to your computer and use it in GitHub Desktop.
Save lholmquist/81de9737b5c91367aa3c to your computer and use it in GitHub Desktop.
Data Sync
// Create a New Data Sync Object
var dataSync = AeroGear.DataSync( { syncServerUrl: "http://localhost:8080" } );
/* possibly more options here, like "auto-merge"
options = {
syncServerUrl: "link_to_sync_server",
autoMerge: false, //optional, defaults to false? Not sure this is the right spot for this, maybe should be in the update call
otheroptions: ....
}
*/
// Probably have 3 Methods: read, save( Update ), remove
// each one has 2 parameters, the "document" and the settings
/*
The document here is an object defined like in qmx's sync thought dump
var document = {
id: "123sjf2-i",
content: {
// Some Arbitrary JSON or an array or something serializable into JSON
},
rev: "SOME_REVISION_ID" // or rev_id or revision or revision_id, we can argue over names later
}
*/
dataSync.read( document, settings );
/*
--READ--
document is optional and if left out, will be a "read all" method
var settings = {
success: function( document ){}, // GET the document
error: function( error ){} // an error happened GETting the document, like it can't be found or something
}
*/
dataSync.save( document, settings );
/*
--Save--
document can be either an array or an object
if whatever is passed is in the form of the document specifed above, then save works as an "update"
var settings: {
autoMerge: // not sure if this should be here or in the constructor
success: function( document ){} // successful PUT to create the document or update the document,
conflict: function( error, current_model_from_server, delta_of_current_server_model_and_local_document ) // this delta thing should be nice and user friendly or something
SOME_OTHER_SPECIFIC_CALLBACK: function(){}, // Maybe other callbacks for specific events
error: function( error ){} // an error happened, catch-all ?
}
*/
dataSync.remove( document, settings );
/*
TBD
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment