mirror of
https://github.com/comatory/fb2iCal
synced 2025-06-05 22:09:25 +02:00
feature: create event store in preparation of table component
replacement
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { configStore } from '../stores'
|
||||
import { configStore, eventStore } from '../stores'
|
||||
|
||||
const STORAGE_KEYS = {
|
||||
export const STORAGE_KEYS = {
|
||||
CONFIG: 'fb-to-ical-config',
|
||||
EVENTS: 'fb-to-ical-events',
|
||||
}
|
||||
|
||||
class StorageListener {
|
||||
@@ -13,10 +14,12 @@ class StorageListener {
|
||||
window.addEventListener('storage', this._handleStorageChange)
|
||||
|
||||
const unsubscribeConfigStore = configStore.subscribe(this._handleConfigStoreChange)
|
||||
const unsubscribeEventStore = eventStore.subscribe(this._handleEventStoreChange)
|
||||
|
||||
this._storeSubscribers = new Set([
|
||||
...this._storeSubscribers,
|
||||
unsubscribeConfigStore,
|
||||
unsubscribeEventStore,
|
||||
])
|
||||
}
|
||||
|
||||
@@ -32,6 +35,9 @@ class StorageListener {
|
||||
case STORAGE_KEYS.CONFIG:
|
||||
configStore.set(JSON.parse(event.newValue))
|
||||
break
|
||||
case STORAGE_KEYS.EVENTS:
|
||||
eventStore.set(JSON.parse(event.newValue))
|
||||
break
|
||||
default:
|
||||
return
|
||||
}
|
||||
@@ -40,6 +46,10 @@ class StorageListener {
|
||||
_handleConfigStoreChange(value) {
|
||||
localStorage.setItem(STORAGE_KEYS.CONFIG, JSON.stringify(value))
|
||||
}
|
||||
|
||||
_handleEventStoreChange(value) {
|
||||
localStorage.setItem(STORAGE_KEYS.EVENTS, JSON.stringify(value))
|
||||
}
|
||||
}
|
||||
|
||||
export default new StorageListener()
|
||||
|
Reference in New Issue
Block a user