Skip to content
This repository has been archived by the owner on Sep 30, 2023. It is now read-only.

'data' event (from readme) does not exist #42

Open
deanpress opened this issue Dec 17, 2020 · 0 comments
Open

'data' event (from readme) does not exist #42

deanpress opened this issue Dec 17, 2020 · 0 comments
Assignees

Comments

@deanpress
Copy link

deanpress commented Dec 17, 2020

The readme describes db.events.on('data', (dbname, event) => ... ) as a way to listen for new data entries/updates, but this event does not exist.

Currently, it looks like you'd have to do this to get the latest entry:

    db.events.on('replicated', (address) => {
      const entry = db.get('')[0];
      console.log(entry);
    })

The problem with this is, if you restart the process, it'll retrieve the latest stored entry for each (existing) entry. Also you can't get the most recently updated entry this way when an existing document is updated. You'd have to keep an updated_at entry so you can query the highest value.

Alternatively you can use the replicate.progress event and read entry.payload.value, but when the process restarts, the data is fired newest to oldest, while oldest to newest would also be a common use case, e.g. for building a separate state or database.

      db.events.on('replicate.progress', (address, hash, entry, progress, total) => {
        console.log(entry.payload.value);
      })

Having the on('data', dbname, event) event as described in the readme would be much more efficient.

@deanpress deanpress changed the title 'data' event does not exist 'data' event (from readme) does not exist Dec 17, 2020
@aphelionz aphelionz self-assigned this Feb 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants