[GH-ISSUE #30] Stopping a live data proxies' onChange subscription cancels others #13

Closed
opened 2026-05-23 08:36:32 -06:00 by gitea-mirror · 0 comments
Owner

Originally created by @appy-one on GitHub (Jan 5, 2023).
Original GitHub issue: https://github.com/appy-one/acebase-core/issues/30

Originally assigned to: @appy-one on GitHub.

When adding multiple onChange handlers to a live data proxy, stopping 1 actually stops them all
Example:

const proxy = await db.ref('books/book1').proxy();
const book = proxy.value;

const subscription1 = book.onChanged((val, prev) => {
  // I must keep getting these notifications
});
const subscription2 = book.onChanged((val, prev) => {
  // I'm just here shortly
});

book.title = 'New title';
// subscription1 and subscription2 are both triggered

subscription2.stop(); // <-- this causes subscription1 to be stopped too

book.title = 'Original title';
// no subscriptions are triggered!

The problem is caused in data-proxy.ts:466 - the .off('mutations') removes all handlers and should have never been in there

Originally created by @appy-one on GitHub (Jan 5, 2023). Original GitHub issue: https://github.com/appy-one/acebase-core/issues/30 Originally assigned to: @appy-one on GitHub. When adding multiple `onChange` handlers to a live data proxy, stopping 1 actually stops them all Example: ```js const proxy = await db.ref('books/book1').proxy(); const book = proxy.value; const subscription1 = book.onChanged((val, prev) => { // I must keep getting these notifications }); const subscription2 = book.onChanged((val, prev) => { // I'm just here shortly }); book.title = 'New title'; // subscription1 and subscription2 are both triggered subscription2.stop(); // <-- this causes subscription1 to be stopped too book.title = 'Original title'; // no subscriptions are triggered! ``` The problem is caused in [data-proxy.ts:466](https://github.com/appy-one/acebase-core/blob/f96f3b2327a149e628a57f4e1fdd40d73d9bcf5d/src/data-proxy.ts#L466) - the `.off('mutations')` removes all handlers and should have never been in there
gitea-mirror 2026-05-23 08:36:32 -06:00
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-core#13
No description provided.