appy-one / acebase-client

Client to connect to remote AceBase NoSQL database server
MIT License
20 stars 8 forks source link

Properly closing live query #50

Closed appy-one closed 1 year ago

appy-one commented 2 years ago

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 commented 2 years ago

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

TELECI-PROJECT commented 1 year ago

Hi, I was trying out this today,

this is my setup: acebase-server@1.11.0 acebase@1.21.7

I was connecting to AceBase server using a web app built on ReactJS with the browser client: https://cdn.jsdelivr.net/npm/acebase-client@1.17.0/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

appy-one commented 1 year ago

Thanks for reporting, I'll look into it asap

appy-one commented 1 year ago

I'm moving this issue to the acebase client repo

appy-one commented 1 year ago

Looks like I was too quick to draw - this originally was an acebase issue. @TELECI-PROJECT you were have an issue using acebase-client v1.17.0 browser dist. Have you updated to the latest version to check if the issue has been resolved in the meantime?

TELECI-PROJECT commented 1 year ago

Hi, thanks, I don't see any errors in console after updating to the latest version (Acebase Client v1.20 and Acebase v1.27).

appy-one commented 1 year ago

Great!

Spread the word contribute Sponsor AceBase