wxt-dev / wxt

⚡ Next-gen Web Extension Framework
https://wxt.dev
MIT License
4.43k stars 184 forks source link

Single watcher for multiple keys #999

Open avi12 opened 1 month ago

avi12 commented 1 month ago

Feature Request

This snippet allows for watching a single item: https://github.com/wxt-dev/wxt/blob/c0aa12089e24c9f0cb01fb3f8546f17096b21341/packages/wxt/src/storage.ts#L434-L447

I also wish to have a watcher setup like this:

const unwatch = storage.watch({
  "local:item1"((newValue, oldValue) => {...}),
  "local:item2"((newValue, oldValue) => {...})
});
unwatch();

Is your feature request related to a bug?

N/A

What are the alternatives?

storage.watch("local:item1", (newValue, oldValue) => {...});
storage.watch("local:item2", (newValue, oldValue) => {...});

Additional context

This functionality is available in Plasmo

aklinker1 commented 1 month ago

We can add something like that!

But for most cases, I would recommend just calling watch multiple times. Seems like a classic case of premature optimization.

avi12 commented 1 month ago

In my case it's not for the sake of premature optimization but rather increased readability and maintainability, having all of the watchers in one place

Timeraa commented 1 month ago

Since I have a PR open about some storage changes, I'll take this and add that to the watch