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

storage.onChanged clarrification #18326

Merged
merged 3 commits into from
Aug 10, 2022

Conversation

rebloor
Copy link
Contributor

@rebloor rebloor commented Jul 13, 2022

Summary

Clarifies the behavior of and data returned by storage.onChanged. Provides the content requested in Bug 1621162.

Metadata

This PR…

  • Adds a new document
  • Rewrites (or significantly expands) a document
  • Fixes a typo, bug, or other error

@rebloor rebloor added the Content:WebExt WebExtensions docs label Jul 13, 2022
@rebloor rebloor requested a review from rpl July 13, 2022 18:17
@rebloor rebloor self-assigned this Jul 13, 2022
@rebloor rebloor requested a review from a team as a code owner July 13, 2022 18:17
@github-actions github-actions bot added the Content:Other Any docs not covered by another "Content:" label label Jul 13, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Jul 13, 2022

Preview URLs

Flaws

None! 🎉

External URLs

URL: /en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage/onChanged
Title: storage.onChanged
on GitHub

No new external URLs

(this comment was updated 2022-08-10 17:18:13.710708)

Copy link
Member

@rpl rpl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rebloor looks good but there is a small fix to be applied (mentioning also remove and clear as methods that triggers an onChanged event to be fire) and a small proposed tweak to the clarification paragraph that follows.

@@ -15,7 +15,9 @@ browser-compat: webextensions.api.storage.onChanged
---
{{AddonSidebar()}}

Fired when one or more items change.
Fired when {{WebExtAPIRef('storage.StorageArea.set','storageArea.set')}} executes against a storage area.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rebloor technically the onChanged event would also be fired in response to calls to the remove and clear methods, and so we should mention them here along with set.

I also confirmed that the clarification paragraph that follows (related to the behavior to expect when set is called) should be ok as is:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rpl can I clarify, do remove and clear triggers also result in all the keys being returned or just the keys that were removed or cleared?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rpl can I clarify, do remove and clear triggers also result in all the keys being returned or just the keys that were removed or cleared?

They both fire an event only if something has been removed (or cleared), from the perspective of what is included in the changes emitted in an onChanged event:

  • on remove calls: only the keys removed are expected to be included
  • on clear calls: we will remove everything and so the changes emitted will technically include all stored keys (if there wasn't any then onChanged wouldn't be fired).

Fired when one or more items change.
Fired when {{WebExtAPIRef('storage.StorageArea.set','storageArea.set')}} executes against a storage area.

As this event is triggered by {{WebExtAPIRef('storage.StorageArea.set','storageArea.set')}}, it's possible to receive a callback when there is no change to the underlying data. Also, the information returned includes all keys within the storage area {{WebExtAPIRef('storage.StorageArea.set','storageArea.set')}} ran against. Your code needs to determine what changes have occurred by examining the content of the `changes` argument.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, I'm wondering if we could reword a bit "Your code needs to determine ..." to say something like The extension may determine what changes have occurred by examining the content of the changesargument received by theonChanged listeners.. wdyt?

@rebloor rebloor requested a review from rpl August 1, 2022 00:14

- `changes`
- : `object`. Object describing the change. This contains one property for each key that changed. The name of the property is the name of the key that changed, and its value is a {{WebExtAPIRef('storage.StorageChange')}} object describing the change to that item.
- : `object`. Object describing the change. This object contains properties for all the keys in the storage area where {{WebExtAPIRef('storage.StorageArea.set','storageAred.set')}} occurred. The name of each property is the name of each key. The value of each key is a {{WebExtAPIRef('storage.StorageChange')}} object describing the change to that item.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed that this is currently saying "all the keys in the storage area where set occurred", but the actual behavior is that the changes object will contains all keys that where included in the set call, even if the old and new value may still be the same.

Any other key stored in the same area that was not part of what was passed to the set call will still not be part of the changes object.

would you mind to tweak that part?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

@rpl rpl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@rebloor rebloor merged commit 9cb3885 into mdn:main Aug 10, 2022
@rebloor rebloor deleted the storage.onChanged-clarrification branch August 10, 2022 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:Other Any docs not covered by another "Content:" label Content:WebExt WebExtensions docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants