acebase
acebase copied to clipboard
Properly closing live query
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?
This has been added in acebase v1.21.0+ and acebase-client v1.16.0+ (or older version using latest acebase-core)
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
Thanks for reporting, I'll look into it asap