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

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

Open
@deanpress

Description

@deanpress

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy