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

[Feature Request] Add GetKeys()/RemoveKeys methods #124

Closed
Pjotrtje opened this issue Feb 14, 2021 · 3 comments
Closed

[Feature Request] Add GetKeys()/RemoveKeys methods #124

Pjotrtje opened this issue Feb 14, 2021 · 3 comments
Labels
Feature New feature that will be added to the project Resolved: Completed The issue has been resolved

Comments

@Pjotrtje
Copy link

Is your feature request related to a problem? Please describe.
I am porting a ReactJS website to Blazor and due to 'reasons' I store data with 'random' keys which I want to delete every x days. (this is vague I know). The easiest way is to compare all the keys in store with keys I 'allow' and then remove unwanted data by key.

Describe alternatives you've considered
I can fix this now by:
int Length(); -> foreach index -> string Key(int index); -> and depending on an if call: void RemoveItem(string key);

So when I have 100 keys in store and I have to remove 50. I will have to make 1 + 100 + 50 = 151 calls to JS interop.

Describe the solution you'd like
If there were also IEnumerable<string> GetKeys() + void RemoveKeys(IEnumerable<string> keys)

Then I could achieve the same with just 2 calls. Which is nicer, more readable and faster.

var toRemoveKeys = localStorage.GetKeys().Except(allowedKeys);
localStorage.RemoveKeys(toRemoveKeys);

Additional context
I describe it here as sync buth it would of cource also be nice in async.

FYI, code in my ReacttJS (TypeScript) app:

Object
    .keys(localStorage)
    .filter(k => !allowedKeys.includes(k))
    .forEach(r => localStorage.removeItem(r));
@Pjotrtje Pjotrtje added Feature Request Request to add a new feature Triage Issue needs to be triaged labels Feb 14, 2021
@megafetis
Copy link

megafetis commented May 23, 2021

Yes I need too

koskila added a commit to koskila/LocalStorage that referenced this issue Oct 10, 2021
…e keys and returning all keys from local storage
chrissainty pushed a commit that referenced this issue Oct 31, 2021
@steamonimo
Copy link

I need the enumeration via GetKeys as well

@chrissainty
Copy link
Member

Fixed in #162

@chrissainty chrissainty added Feature New feature that will be added to the project Resolved: Completed The issue has been resolved and removed Feature Request Request to add a new feature Triage Issue needs to be triaged labels Aug 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature that will be added to the project Resolved: Completed The issue has been resolved
Projects
None yet
Development

No branches or pull requests

4 participants