nextcloud-libraries / nextcloud-libraries/nextcloud-browser-storage

[Feature Request] Provide a way to listen `storage` event

Open
#555 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

1. to develop enhancement
Dominant language
JavaScript
Stars
5
Forks
0
Avg merge
5m
Merged PRs (30d)
12

Description

Problem

There is no clean way to listen for a specific BrowserStorage instance storage event

Proposal 1: make scopeKey public

https://github.com/nextcloud-libraries/nextcloud-browser-storage/blob/8379a79b62109c08f57f3498edb028e126961015/lib/scopedstorage.ts#L19-L21

Providing it as a public property allows filtering the storage events manually to handle only a specific browserStorage instance.

Proposal 2: provide a method to subscribe for the storage event

Option 1: add onStorage method
class ScopedStorage implements NextcloudStorage {
  onStorage(key: string, callback) {
  onStorage(callback) {
    const callbackWithFilter = () => {...}

    window.addEventListener('storage', callbackWithFilter)

    return () => window.removeEventListener('storage', callbackWithFilter)
  }

  offStorage(callback) {
    // callback should be stored in a Map
  }
}
Option 2: provide additional functions
declare function onBrowserStorageChange(browserStorage: ScopedStorage, key?: string, callback)
declare function onBrowserStorageChange(browserStorage: ScopedStorage, callback)
Option 3: extend EventTarget
class ScopedStorage implements NextcloudStorage extends EventTarget {
  // Override `addEventListener` and `removeEventListener`
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with lib/scopedstorage.ts, especially the scopeKey definition referenced in the issue, and inspect how ScopedStorage relates to the browser storage event. Compare the proposed public property, subscription methods, and EventTarget approaches, then determine which API the project should adopt and how callers would unsubscribe or filter by key. Done means a decided, documented way to listen for changes from one ScopedStorage instance.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.