Changes

Jump to: navigation, search

CloudServices/Sync/FxSync/Developer/ClientAPI

1,789 bytes added, 02:00, 30 January 2009
Writing a Tracker class
== Writing a Tracker class ==
Your tracker class must inherit from <tt>Tracker</tt>, which is defined in <tt>weave/engines/trackers.js</tt>.
 
Your tracker has to maintain two critical pieces of information. One is a list of GUIDs for objects that have been changed and therefore require syncing. The other is a "score", which is a number from 0 to 100 which represents "how badly does this data type need to be synced right now".
 
You will probably want to register your tracker as an observer, to get notified by Mozilla when it does something you care about. What events you listen for is entirely up to you. You can find out more about registering as an observer here: [link].
 
=== The Score ===
 
The '''score''' is stored in <tt>this._score</tt>, a variable defined by the base Tracker class. Set your score by assigning a value to <tt>this._score</tt>.
 
The score number is used by the scheduler to decide when your engine will be synced. Setting it to zero means "I have no need to sync". The higher you set this number, the more urgently the scheduler treats your request. Setting it to 100 means "Sync me immediately". It's up to you to figure out the best way to assign a score based on the current state of whatever data type you're tracking.
 
Your tracker score is automatically reset to zero after each time your engine syncs.
 
=== The changed GUID list ===
 
The base class maintains a list of GUIDs that need syncing. When your tracker detects that an item has changed, you should add it to this list by calling:
 
this.addChangedID(guid);
 
These GUIDs correspond to the <tt>.id</tt> fields of your Record objects; see the section on the Store class for more about defining and maintaining the mapping between GUIDs and Records.
 
=== Example ===
 
Here's the skeleton of a sample Tracker class.
<pre>
1,007
edits

Navigation menu