frontend: add generic StorageItemStore
This commit is contained in:
parent
704b35ae2b
commit
a725e46ff0
1 changed files with 8 additions and 5 deletions
|
@ -45,6 +45,13 @@ class Store {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class StorageItemStore extends Store {
|
||||||
|
constructor(key) {
|
||||||
|
super(getItem(key), `StorageItemStore[key=${key}]`);
|
||||||
|
this.watch(e => setItem(key, e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class ChannelsStore extends Store {
|
class ChannelsStore extends Store {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(gateway.channels || [], "ChannelsStore");
|
super(gateway.channels || [], "ChannelsStore");
|
||||||
|
@ -309,7 +316,7 @@ export const selectedChannel = new Store({ id: getItem("app:cache:openChannelId"
|
||||||
export const showSidebar = new Store(false, "showSidebar");
|
export const showSidebar = new Store(false, "showSidebar");
|
||||||
export const showChannelView = new Store(true, "showChannelView");
|
export const showChannelView = new Store(true, "showChannelView");
|
||||||
export const smallViewport = new Store(false, "smallViewport");
|
export const smallViewport = new Store(false, "smallViewport");
|
||||||
export const theme = new Store(getItem("app:visual:theme"), "theme");
|
export const theme = new StorageItemStore("app:visual:theme");
|
||||||
export const channels = new ChannelsStore();
|
export const channels = new ChannelsStore();
|
||||||
export const gatewayStatus = new GatewayStatusStore();
|
export const gatewayStatus = new GatewayStatusStore();
|
||||||
export const messagesStoreProvider = new MessagesStoreProvider();
|
export const messagesStoreProvider = new MessagesStoreProvider();
|
||||||
|
@ -332,7 +339,3 @@ export const allStores = {
|
||||||
selectedChannel.watch((newSelectedChannel) => {
|
selectedChannel.watch((newSelectedChannel) => {
|
||||||
setItem("app:cache:openChannelId", newSelectedChannel.id);
|
setItem("app:cache:openChannelId", newSelectedChannel.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
theme.watch((newTheme) => {
|
|
||||||
setItem("app:visual:theme", newTheme);
|
|
||||||
});
|
|
||||||
|
|
Loading…
Reference in a new issue