Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Change" event to subscribe to so extension pages can update each other #63

Open
tdriley opened this issue Sep 2, 2022 · 2 comments
Open

Comments

@tdriley
Copy link

tdriley commented Sep 2, 2022

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?

@fregante
Copy link
Owner

fregante commented Sep 2, 2022

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.

@fregante fregante changed the title Feature request: "Change" event to subscribe to so extension pages can update each other "Change" event to subscribe to so extension pages can update each other Sep 2, 2022
@fregante
Copy link
Owner

fregante commented Sep 2, 2022

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 

});

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

No branches or pull requests

2 participants