-
-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Library is crashing while firing it's change event on query #61
Comments
Thanks for reporting, I'll take a look |
I managed to reproduce the error, looks like a bit of refactoring on my end is needed to fix it. A very quick fix for you would be to edit line 866 in api-local.js, change Let me know if that works for now. |
By the way, I see that you are manually refreshing the data in your code upon changes, but that is not necessary. The essence of a realtime query is that your query results are updated in realtime, so you don't have to execute the query again after changes. See the following example: const fiveStarBooks = {}; // local query result set
const snaps = await db.query('books')
.filter('rating', '==', 5)
.on('add', match => {
// add book to results
fiveStarBooks[match.snapshot.key] = match.snapshot.val();
})
.on('change', match => {
// update book details
fiveStarBooks[match.snapshot.key] = match.snapshot.val();
})
.on('remove', match => {
// remove book from results
delete fiveStarBooks[match.ref.key];
})
.get();
// Add current query results to our local result set
snaps.forEach(snap => {
fiveStarBooks[snap.key] = snap.val();
}); The |
I did this way, because I had applied sort() based on the time in
descending order on the database reference, which is lost if I do it in the
way you suggested.
At this moment I have edited my code to update at,
"bpm", with data {<chid id>:{...oldData, ...newData}}
previously I was updating at,
"bpm/<child id>", with data {...newData}
now I am getting no benifit of update(), since it is working same as the
set(), I hope the problem will be fixed on the next update of the library,
I will update it then.
…On Wed, Jan 26, 2022, 9:30 PM Ewout Stortenbeker ***@***.***> wrote:
By the way, I see that you are manually refreshing the data in your code
upon changes, but that is not necessary. The essence of a realtime query is
that your query results are updated in realtime, so you don't have to
execute the query again after changes. See the following example:
const fiveStarBooks = {}; // local query result setconst snaps = await db.query('books')
.filter('rating', '==', 5)
.on('add', match => {
// add book to results
fiveStarBooks[match.snapshot.key] = match.snapshot.val();
})
.on('change', match => {
// update book details
fiveStarBooks[match.snapshot.key] = match.snapshot.val();
})
.on('remove', match => {
// remove book from results
delete fiveStarBooks[match.ref.key];
})
.get();
// Add current query results to our local result setsnaps.forEach(snap => {
fiveStarBooks[snap.key] = snap.val();});
The add, change and remove callbacks update the local state without
executing the query again
—
Reply to this email directly, view it on GitHub
<#61 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEHHUAG7Q7VTMTV6O76JYW3UYALA5ANCNFSM5MXOZDJQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
It's a little unclear to me why you would do your updates on a different target? The node you are updating has no effect on events firing, and has no effect on a realtime query either? |
I just published acebase version 1.15.0, let me know if it works |
I had set sort, filter and change listener at the node "/bpm";
function gotMatches(snaps) {
const data={};
snaps.forEach(snap => {
data[snap.key] = snap.val();
});
lis(data);
}
const valueChanged=() => {
db.get({include, exclude}).then(gotMatches).catch(err);
};
function matchAdded() {
valueChanged();
}
function matchChanged() {
valueChanged();
}
function matchRemoved() {
valueChanged();
}
db
.on('add', matchAdded)
.on('change', matchChanged)
.on('remove', matchRemoved);
valueChanged();
[database] Reading node "/bpm/kytk61qh001doazk0c46fvkr" from address 0,10
0|index | [database] Node "/bpm/kytk61qh001doazk0c46fvkr" being updated: adding 0 keys (), updating 1 keys ("value"), removing 0 keys ()
0|index | [database] Node "/bpm/kytk61qh001doazk0c46fvkr" saved at address 0,10 - 1 addresses, 50 bytes written in 1 chunk(s)
0|index | TypeError: Cannot convert undefined or null to object
0|index | at Function.keys ()
0|index | at Object.childChangedCallback [as callback] (/Local Tcp Server/node_modules/acebase/src/api-local.js:728:60)
0|index | at /Local Tcp Server/node_modules/acebase/src/storage.js:494:25
0|index | at Array.forEach ()
0|index | at Object.trigger (/Local Tcp Server/node_modules/acebase/src/storage.js:493:18)
0|index | at /Local Tcp Server/node_modules/acebase/src/storage.js:1066:51
0|index | at Array.forEach ()
0|index | at triggerAllEvents (/Local Tcp Server/node_modules/acebase/src/storage.js:1012:14)
0|index | at processTicksAndRejections (node:internal/process/task_queues:78:11)
PM2 | App [index:0] exited with code [1] via signal [SIGINT]
The text was updated successfully, but these errors were encountered: