"Change" event to subscribe to so extension pages can update each other
Closed this issue · 2 comments
I'm interested in migrating over to this from https://github.com/tshaddix/webext-redux but I need something that lets me subscribe to changes to stored data when they are set from other parts of the extension.
Would this be something that can be added, theoretically?
It's already kind of possible but there's no way to find what changed exactly:
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage/onChanged
chrome.storage.onChanged.addListener(async (changes, area) => {
if (!changes.options || area !== 'sync') {
return;
}
console.log('the options were updated', await optionsSync.getAll())
});
At a minimum I can export a method that lets you manually parse the zipped changes.options.oldValue
string so you can access it and diff it yourself. That would be an easy feature.
Adding a optionsStora.onChange
event would be a bit more involved, but I'd accept a PR too, as long as reasonable in size.
Oh actually the decode is already exported:
chrome.storage.onChanged.addListener((changes, area) => {
if (!changes.options || area !== 'sync') {
return;
}
const old = optionsStorage._decode(changes.options.oldValue);
const new = optionsStorage._decode(changes.options.newValue);
// Run your own diffing
});