From f9f78b867c01d7487bc2d41593e64bf60c2a9441 Mon Sep 17 00:00:00 2001 From: Richard Date: Tue, 18 May 2021 11:52:36 +0100 Subject: [PATCH] Tidied up setTabProperty I was doing nasty things with a for loop - we've replaced it with a map statement, which achieves the same thing but works better with Vue.js reactivity. --- openflexure_microscope/api/static/src/store.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/openflexure_microscope/api/static/src/store.js b/openflexure_microscope/api/static/src/store.js index 5755e8c5..00581953 100644 --- a/openflexure_microscope/api/static/src/store.js +++ b/openflexure_microscope/api/static/src/store.js @@ -38,20 +38,23 @@ const moduleImjoy = { } }, /** - * Set a parameter on any matching tab objects + * Set a parameter on the tab with a given id + * + * Payload should contain: + * tab: ID of the tab to modify (not window_id) + * key: name of the property to add/change + * value: value of the property to add/change */ setTabProperty(state, payload) { let tab = payload.tab; let key = payload.key; let value = payload.value; - for (let i = 0; i < state.tabs.length; i++) { - let t = state.tabs[i]; - if ((t === tab) | (t.name === tab) | (t.id === tab)) { + state.tabs = state.tabs.map(t => { + if (t.id === tab) { t[key] = value; } - state.tabs.splice(i, 1, t); // This should work nicely with reactive stuff - } - //state.tabs = tablist; // This should force an update + return t; + }); } }, actions: {},