Observer Pattern

All the object types in the SDK have an observe utility function, in place of the previous LiveObject pattern. Observe function is designed to integrate nicely with the useEffect function and allows you to easily retrieve the queried data asynchronously, as well as subscribe to any new changes to the data.

The example above describes the way to use the observer pattern with the message module. If there is any update in the message, the setMessage object will be called to automatically update the messageResult object. messageResult consists of data,error, loading, and pages (for query collections).

Collection

Observer pattern for collection is a little more complex. The observe function retains a similar pattern but has to be used in conjunction with runQuery. While the observe function is used for observing any change that happens to an object, runQuery is used for acquiring the collection and performing pagination.

Last updated