From e1bbe34ff2e5c136892e25d13c7504ac05437b97 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 4 Feb 2022 14:22:50 +0100 Subject: [PATCH] state: add bouncerNetworks helpers --- components/app.js | 11 +++-------- state.js | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/components/app.js b/components/app.js index eb5ed90..6354bdd 100644 --- a/components/app.js +++ b/components/app.js @@ -160,7 +160,6 @@ export default class App extends Component { autoconnect: false, autojoin: [], }, - bouncerNetworks: new Map(), connectForm: true, loading: true, dialog: null, @@ -950,16 +949,12 @@ export default class App extends Component { let isNew = false; this.setState((state) => { - let bouncerNetworks = new Map(state.bouncerNetworks); if (!attrs) { - bouncerNetworks.delete(id); + return State.deleteBouncerNetwork(state, id); } else { - let prev = bouncerNetworks.get(id); - isNew = prev === undefined; - attrs = { ...prev, ...attrs }; - bouncerNetworks.set(id, attrs); + isNew = !state.bouncerNetworks.has(id); + return State.storeBouncerNetwork(state, id, attrs); } - return { bouncerNetworks }; }, () => { if (!attrs) { let serverID = this.serverFromBouncerNetwork(id); diff --git a/state.js b/state.js index 7cada74..f1d5a7b 100644 --- a/state.js +++ b/state.js @@ -172,6 +172,7 @@ export const State = { servers: new Map(), buffers: new Map(), activeBuffer: null, + bouncerNetworks: new Map(), }; }, updateServer(state, id, updater) { @@ -302,6 +303,19 @@ export const State = { let buffers = new Map(bufferList.map((buf) => [buf.id, buf])); return [id, { buffers }]; }, + storeBouncerNetwork(state, id, attrs) { + let bouncerNetworks = new Map(state.bouncerNetworks); + bouncerNetworks.set(id, { + ...bouncerNetworks.get(id), + ...attrs, + }); + return { bouncerNetworks }; + }, + deleteBouncerNetwork(state, id) { + let bouncerNetworks = new Map(state.bouncerNetworks); + bouncerNetworks.delete(id); + return { bouncerNetworks }; + }, handleMessage(state, msg, serverID, client) { function updateServer(updater) { return State.updateServer(state, serverID, updater);