Skip to content

Acess to value on watch callback when available #341

Open

Description

@nnx0r

Describe the feature

I find it weird that watch method doesn't actually provide me k:v pair for example.
Is there any specific reasoning why watcher strictly returns only event and key and can't be customized further?

Building a browser storage driver is not quite good this way. I'd expect in watcher to receive a key and value on update and only key on delete, for example.

With current implementation, I'd need to get the value from the storage, using the key it provides me with, which seem like overhead?

Additional information

  • Would you be willing to help implement this feature?

Activity

  1. changed the title [-]Make watch callback more flexible?[/-] [+]Acess to value on watch callback when available[/+] on May 1, 2024
  2. added
    enhancement
    on May 1, 2024
  3. pwFoo commented on Dec 31, 2024

    @pwFoo

    Hello,
    played arround with unstorage and it should take over and replace some of my features code parts out of the box!
    Thanks for that awesome project 🥇 👍

    watch could much more powerful with callback arguments changed to (key, value, oldValue, event) => {}.

    1. value: Because value should be available during save data and trigger event a get overhead can be avoided?
    2. oldValue: Would be cool for some use cases and helps to have more precise event type (added, updated or deleted) and more flexibility?
    3. event filtering: Ok, just optional if easy to implement because it could be done by a wrapper arround the watch callback... filtering events by key match or regexp / wildcard based filter functions to listen to specific changes

    I would love to see value and oldValue for my needs :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions