From d5e015c1d3ce9a0efb4790fd719f9166b204a3da Mon Sep 17 00:00:00 2001 From: Ricardo Hernandez-Montoya Date: Tue, 25 Apr 2017 18:14:29 +0200 Subject: [PATCH] Issue #44 proper start and stop simulator running detection --- src/stores/simulator-store.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/stores/simulator-store.js b/src/stores/simulator-store.js index 69303b3..34fabfa 100644 --- a/src/stores/simulator-store.js +++ b/src/stores/simulator-store.js @@ -20,8 +20,18 @@ class SimulatorStore extends ArrayStore { var simulator; switch (action.type) { + + case 'simulators/added': + SimulatorsDataManager.startRunningDetection(action.data); + + return super.reduce(state, action); + + case 'simulators/removed': + SimulatorsDataManager.stopRunningDetection(action.original); + + return super.reduce(state, action); + case 'simulators/loaded': - //case 'simulators/is-running': // get simulator running state if (Array.isArray(action.data)) { action.data.forEach((simulator) => { @@ -35,12 +45,10 @@ class SimulatorStore extends ArrayStore { case 'simulators/running': // check if simulator running state changed - simulator = state.find(element => { - return element._id === action.simulator._id; - }); + simulator = state.find(element => element._id === action.simulator._id ); // only update if state changed - if (simulator.running == null || simulator.running !== action.simulator.running) { + if (simulator && simulator.running !== action.simulator.running) { state = this.updateElements(state, [ action.simulator ]); }