canmove, Confirmed users
725
edits
Line 72: | Line 72: | ||
</pre> | </pre> | ||
== | == The Store object == | ||
The Store object (which extends <tt>Store</tt>, as defined in <tt>services/sync/modules/engines.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 | The Store object (which extends <tt>Store</tt>, as defined in <tt>services/sync/modules/engines.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 based on incoming Record objects. The majority of the code you write for syncing a new data type will most likely be in the Store implementation. | ||
Each Record that the Store keeps track of must be identified by a unique ID (unique among all records in the store) called GUID. 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 (note that GUIDs must be allowed to change and should be URL friendly). If not, you may have to invent your own mapping from data objects to GUIDs as long as it's consistent. In this case, it is highly recommended to use the <tt>Utils.makeGUID()</tt> helper to generate new GUIDs: | |||
Each Record that the Store keeps track of must be identified by a unique ID (unique among all records in the store) called GUID. 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 as long as it's consistent. In this case, it is highly recommended to use <tt>Utils.makeGUID()</tt> helper: | |||
let newGuid = Utils.makeGUID(); | let newGuid = Utils.makeGUID(); | ||
Your Store object '''must''' implement the following methods: | Your Store object '''must''' implement the following methods: | ||
Line 99: | Line 95: | ||
=== createRecord === | === createRecord === | ||
The <tt>createRecord( id, collection )</tt> method gets called by the engine to request a new record for an item with a given GUID. It's your Store's responsibility to instantiate a Record object | The <tt>createRecord( id, collection )</tt> method gets called by the engine to request a new record for an item with a given GUID. It's your Store's responsibility to instantiate a Record object, assign the given GUID, and return it. | ||
=== itemExists(guid) === | === itemExists(guid) === | ||
Line 135: | Line 131: | ||
:TODO | :TODO | ||
=== Example Store | === Example Store skeleton === | ||
<pre> | <pre> |