[GH-ISSUE #61] Library is crashing while firing it's change event on query #45

Closed
opened 2026-05-23 08:27:54 -06:00 by gitea-mirror · 6 comments
Owner

Originally created by @directtosumit on GitHub (Jan 25, 2022).
Original GitHub issue: https://github.com/appy-one/acebase/issues/61

Originally assigned to: @appy-one on GitHub.

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]

Originally created by @directtosumit on GitHub (Jan 25, 2022). Original GitHub issue: https://github.com/appy-one/acebase/issues/61 Originally assigned to: @appy-one on GitHub. 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 (<anonymous>) 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 (<anonymous>) 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 (<anonymous>) 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]
gitea-mirror 2026-05-23 08:27:54 -06:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@appy-one commented on GitHub (Jan 25, 2022):

Thanks for reporting, I'll take a look

<!-- gh-comment-id:1021210788 --> @appy-one commented on GitHub (Jan 25, 2022): Thanks for reporting, I'll take a look
Author
Owner

@appy-one commented on GitHub (Jan 26, 2022):

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 'notify_child_changed' to 'child_changed'. Make the same edit in line 715.

Let me know if that works for now.

<!-- gh-comment-id:1022335869 --> @appy-one commented on GitHub (Jan 26, 2022): 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](https://github.com/appy-one/acebase/blob/15e42e3fdd530275573f203e659b604ffcb1b829/src/api-local.js#L866), change `'notify_child_changed'` to `'child_changed'`. Make the same edit in [line 715](https://github.com/appy-one/acebase/blob/15e42e3fdd530275573f203e659b604ffcb1b829/src/api-local.js#L715). Let me know if that works for now.
Author
Owner

@appy-one commented on GitHub (Jan 26, 2022):

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 add, change and remove callbacks update the local state without executing the query again

<!-- gh-comment-id:1022341726 --> @appy-one commented on GitHub (Jan 26, 2022): 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: ```javascript 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 `add`, `change` and `remove` callbacks update the local state without executing the query again
Author
Owner

@directtosumit commented on GitHub (Jan 27, 2022):

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 {:{...oldData, ...newData}}

previously I was updating at,
"bpm/", 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
https://github.com/appy-one/acebase/issues/61#issuecomment-1022341726,
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:
@.***>

<!-- gh-comment-id:1022813765 --> @directtosumit commented on GitHub (Jan 27, 2022): 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 > <https://github.com/appy-one/acebase/issues/61#issuecomment-1022341726>, > 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: > ***@***.***> >
Author
Owner

@appy-one commented on GitHub (Feb 1, 2022):

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?

<!-- gh-comment-id:1026602573 --> @appy-one commented on GitHub (Feb 1, 2022): 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?
Author
Owner

@appy-one commented on GitHub (Feb 21, 2022):

I just published acebase version 1.15.0, let me know if it works

<!-- gh-comment-id:1047094499 --> @appy-one commented on GitHub (Feb 21, 2022): I just published acebase version 1.15.0, let me know if it works
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/acebase#45
No description provided.