acebase icon indicating copy to clipboard operation
acebase copied to clipboard

Properly closing live query

Open appy-one opened this issue 2 years ago • 3 comments

There currently is no way to stop a realtime query from delivering results, besides if returning false in one of the event callbacks. Waiting for a callback to happen might take a long time, so we need way to stop a realtime query upon request.

Suggestion:

const query = db.query('book').filter('rating', '==', ).on('add', bookAdded);
const snaps = await query.get();
// Some time later, stop the realtime query
await query.stop();

Discussed in https://github.com/appy-one/acebase/discussions/108

Originally posted by donl May 22, 2022 When a live query is no longer needed, what is the correct way to unsubscribe and destroy it?

appy-one avatar May 26 '22 14:05 appy-one

This has been added in acebase v1.21.0+ and acebase-client v1.16.0+ (or older version using latest acebase-core)

appy-one avatar Jun 06 '22 12:06 appy-one

Hi, I was trying out this today,

this is my setup: [email protected] [email protected]

I was connecting to AceBase server using a web app built on ReactJS with the browser client: https://cdn.jsdelivr.net/npm/[email protected]/dist/browser.min.js

and I was able to run live query and get updates as described in the documentation.

This is my query: this.db_listener = db.query('items') .filter('locationid', '==', mylocationid) .on('add', (match) => { console.log("Item ADD"); }).on('remove', (match) => { console.log("Item REMOVE"); }).on('change', (match) => { console.log("Item CHANGE"); });

When I'm trying to stop the live query with this: await this.db_listener.stop();

I see this kind of error in console: Uncaught (in promise) ReferenceError: socket is not defined stop browser.min.js:16 stop browser.min.js:16 componentWillUnmount MyComponent.jsx:119

TELECI-PROJECT avatar Sep 06 '22 18:09 TELECI-PROJECT

Thanks for reporting, I'll look into it asap

appy-one avatar Sep 08 '22 20:09 appy-one