Data Store CRUD

Observing Data Changes

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

o associate arguments with your query add them as a paramater.

Swift
Kotlin
JS
Java
C#
C++
Rust
Dart


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.

Swift
Kotlin
JS
Java
C#
C++
Rust
Dart


Accessing Store Observers

To access store observers from the local Ditto store:

Swift
Kotlin
JS
Java
C#
C++
Rust
Dart