frontend: fix array index checks in channels store

This commit is contained in:
hippoz 2022-04-19 02:19:24 +03:00
parent abdaa80d1a
commit ce4592c6c0
No known key found for this signature in database
GPG key ID: 7C52899193467641

View file

@ -30,33 +30,28 @@ class ChannelsStore extends Store {
gateway.subscribe(GatewayEventType.Ready, ({ channels }) => { gateway.subscribe(GatewayEventType.Ready, ({ channels }) => {
this.value = channels; this.value = channels;
this.updated(); this.updated();
}); });
gateway.subscribe(GatewayEventType.ChannelCreate, (channel) => { gateway.subscribe(GatewayEventType.ChannelCreate, (channel) => {
this.value.push(channel); this.value.push(channel);
this.updated(); this.updated();
}); });
gateway.subscribe(GatewayEventType.ChannelDelete, ({ id }) => { gateway.subscribe(GatewayEventType.ChannelDelete, ({ id }) => {
const index = this.value.findIndex(e => e.id === id); const index = this.value.findIndex(e => e.id === id);
if (!index) if (index === -1)
return; return;
this.value.splice(index, 1); this.value.splice(index, 1);
this.updated(); this.updated();
}); });
gateway.subscribe(GatewayEventType.ChannelUpdate, (data) => { gateway.subscribe(GatewayEventType.ChannelUpdate, (data) => {
const index = this.value.findIndex(e => e.id === data.id); const index = this.value.findIndex(e => e.id === data.id);
if (!index) if (index === -1)
return; return;
if (!this.value[index]) if (!this.value[index])
return; return;
this.value[index] = data; this.value[index] = data;
this.updated(); this.updated();
}); });
} }