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`
}
Problem
There is no clean way to listen for a specific
BrowserStorageinstancestorageeventProposal 1: make
scopeKeypublicnextcloud-browser-storage/lib/scopedstorage.ts
Lines 19 to 21 in 8379a79
Providing it as a public property allows filtering the storage events manually to handle only a specific
browserStorageinstance.Proposal 2: provide a method to subscribe for the
storageeventOption 1: add
onStoragemethodOption 2: provide additional functions
Option 3: extend
EventTarget