DataStore.sync()
The sync() method of the DataStore interface opens a cursor that allows you to step through any changes that have taken place in the data store going back to a particular revision ID, and run code in response to different types of change.
#
Syntax#
ReturnsA DataStoreCursor object.
#
ParametersrevisionId
Optional
You can optionally pass sync() a revision ID that specifies the place in the revision history to go back to when running through the tasks. If you don't specify this, it runs through all tasks going back to the beginning of the history.
#
ExampleIn the following example, we create a cursor using sync(), then invoke the runNextTask() function to run the next task in the cursor. In this function, the DataStoreCursor.next method is used to retrieve the next task (a DataStoreTask object), then the manageTask() function checks what type of task it is, and takes action accordingly. In this case, we are either done running through the tasks, in which case we return, or the task is an addition, in which case we run a function to display that addition in the app UI then move on to the next task by running runNextTask() again.