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
Signed by: hippoz
GPG key ID: 7C52899193467641

View file

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