Changes

Jump to: navigation, search

CloudServices/Sync/FxSync/Developer/ClientAPI

1,461 bytes added, 09:06, 30 January 2009
Writing a Store class
== Writing a Store class ==
 
Your Store class (which extends <tt>Store</tt>, as defined in <tt>weave/modules/stores.js</tt>) has the job of creating and maintaining a set of Record objects from the underlying data. The store must also make updates to the underlying data itself, to keep the data up-to-date with the user's latest changes, when the store is instructed to do so.
 
The majority of the code you write for syncing a new data type will most likely be in the Store class.
 
Each Record that the Store keeps track of must be identified by a GUID (Globally Unique ID). Depending of what type of data you're working with, you might already have GUIDs built into your data that you can make use of. If not, you may have to invent your own mapping from data objects to GUIDs. In this case, you will probably find the <tt>makeGUID()</tt> function (in Utils) useful:
 
Cu.import("resource://weave/util.js");
// ...
let newGuid = Utils.makeGUID();
 
Your Store class '''must''' implement the following methods:
 
*<tt>itemExists(id)</tt>
*<tt>createRecord(id)</tt>
*<tt>changeItemId(oldId, newId)</tt>
*<tt>getAllIds()</tt>
*<tt>wipe()</tt>
*<tt>create(record)</tt>
*<tt>update(record)</tt>
*<tt>remove(record)</tt>
 
You may also find it useful to override other methods of the base class, depending on what you're doing.
 
Since this is a lot of methods to write, I'll break them down one by one in the following sub-sections.
 
=== createRecord ===
 
=== itemExists / changeItemId / getAllIds / wipe ===
=== Create / Update / Remove ===
__proto__: Store.prototype,
_logName: "foo",
_lookup: "huh",
itemExists: function(id) {
// Return true if an item with guid = id exists in the store.
1,007
edits

Navigation menu