slightly optimize stores
This commit is contained in:
parent
e1fccd2a66
commit
dcef776d44
1 changed files with 3 additions and 10 deletions
|
@ -15,7 +15,6 @@ class Store {
|
|||
// like subscribe, but without initially calling the handler
|
||||
watch(handler) {
|
||||
const handlerIndex = this._handlers.push(handler) - 1;
|
||||
storeLog(`(${this.name}) (watch/handler) New handler`, this.value);
|
||||
return () => {
|
||||
this._handlers.splice(handlerIndex, 1);
|
||||
};
|
||||
|
@ -23,7 +22,7 @@ class Store {
|
|||
|
||||
subscribe(handler) {
|
||||
const handlerIndex = this._handlers.push(handler) - 1;
|
||||
storeLog(`(${this.name}) (subscribe/initial) Calling handler`, this.value);
|
||||
storeLog(`(${this.name}) (subscribe/initial)`, this.value);
|
||||
handler(this.value);
|
||||
return () => {
|
||||
this._handlers.splice(handlerIndex, 1);
|
||||
|
@ -60,7 +59,7 @@ class ChannelsStore extends Store {
|
|||
gateway.subscribe(GatewayEventType.Ready, ({ channels }) => {
|
||||
this.value = channels;
|
||||
if (getItem("ui:stateful:presistSelectedChannel")) {
|
||||
selectedChannel.set({ id: getItem("state:openChannelId"), name: "none", creator_id: -1 });
|
||||
selectedChannel.value.id = getItem("state:openChannelId");
|
||||
}
|
||||
if (channels.length >= 1) {
|
||||
if (!selectedChannel.value || selectedChannel.value.id === -1) {
|
||||
|
@ -119,15 +118,9 @@ class ChannelsStore extends Store {
|
|||
|
||||
class GatewayStatusStore extends Store {
|
||||
constructor() {
|
||||
super({ open: gateway.open, ready: gateway.authenticated }, "GatewayStatusStore");
|
||||
|
||||
gateway.subscribe(GatewayEventType.Open, () => {
|
||||
this.value.open = true;
|
||||
this.updated();
|
||||
});
|
||||
super({ ready: gateway.authenticated }, "GatewayStatusStore");
|
||||
|
||||
gateway.subscribe(GatewayEventType.Close, () => {
|
||||
this.value.open = false;
|
||||
this.value.ready = false;
|
||||
this.updated();
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue