appy-one / acebase

A fast, low memory, transactional, index & query enabled NoSQL database engine and server for node.js and browser with realtime data change notifications
MIT License
492 stars 27 forks source link

Listening to value data event duplicates parts of mutated event ref path #105

Closed Bubz43 closed 2 years ago

Bubz43 commented 2 years ago
const wait = () => new Promise((resolve) => setTimeout(resolve, 0));

let path = '';
db.ref('recipes').on('mutated', (mutated) => {
  path = mutated.ref.path;
});

const ref = await db.ref('recipes').push({ name: 'cake' });
await wait();

expect(path).toBe('recipes');

await ref.update({ name: 'Cake' });
await wait();

expect(path).toBe(`recipes/${ref.key}/name`);

// Comment out value listener and test passes
db.ref('recipes').on('value', () => {});

await ref.update({ name: 'Bread' });
await wait();

expect(path).toBe(`recipes/${ref.key}/name`);

If listening to the value event the path will be something like recipes/recipe_id/recipe_id/name. The target in mutations event also suffers the same problem. As far as I can tell its just the value event that does this. Everything else, including notify_value, doesn't cause problems.

Also on an unrelated note, but probably not worth opening a second issue for, is the forEach and child methods of MutationsDataSnapshot both call this.val() without passing false, so it warns you to use the methods you already are using.

appy-one commented 2 years ago

Thanks for your detailed report, I'll dive into this!

appy-one commented 2 years ago

Fixed it, published new version 1.19.2. Many thanks for reporting this!

Spread the word contribute Sponsor AceBase