Skip to content

[Feature Request] Provide a way to listen storage event #555

@ShGKme

Description

@ShGKme

Problem

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

Proposal 1: make scopeKey public

private scopeKey(key: string) {
return `${this.scope}${key}`
}

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`
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    1. to developAccepted and waiting to be taken care ofenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions