Observing Data Changes
This article provides an overview and how-to instructions for observing data changes within Ditto.
A store observer is a DQL query that runs continuously and triggers a callback when a change to the store impacts the results of the query.
Store observers are useful when you want to monitor changes from your local Ditto store and react to them immediately. For instance, when your end user updates their profile, asynchronously display changes in realtime.
Setting Up Store Observers
Using the registerObserver
method, set up an observer within the store
namespace enclosed with a query that specifies the collection to watch for changes, as well as your logic to handle the incoming changes.
Store Observer with Query Arguments
To associate arguments with your query add them as a parameter.
Canceling a Store Observer
To cancel a store observer, call cancel
on the observer object.
Once canceled, the store observer will stop processing in the background and will no longer call the provided callback.
Accessing Store Observers
To access store observers from the local Ditto store:
Was this page helpful?