refresh.js (1606B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 "use strict"; 5 6 const { assert } = require("resource://devtools/shared/DevToolsUtils.js"); 7 const { viewState } = require("resource://devtools/client/memory/constants.js"); 8 const { 9 refreshDiffing, 10 } = require("resource://devtools/client/memory/actions/diffing.js"); 11 const snapshot = require("resource://devtools/client/memory/actions/snapshot.js"); 12 13 /** 14 * Refresh the main thread's data from the heap analyses worker, if needed. 15 * 16 * @param {HeapAnalysesWorker} heapWorker 17 */ 18 exports.refresh = function (heapWorker) { 19 return async function ({ dispatch, getState }) { 20 switch (getState().view.state) { 21 case viewState.DIFFING: 22 assert( 23 getState().diffing, 24 "Should have diffing state if in diffing view" 25 ); 26 await dispatch(refreshDiffing(heapWorker)); 27 return; 28 29 case viewState.CENSUS: 30 await dispatch(snapshot.refreshSelectedCensus(heapWorker)); 31 return; 32 33 case viewState.DOMINATOR_TREE: 34 await dispatch(snapshot.refreshSelectedDominatorTree(heapWorker)); 35 return; 36 37 case viewState.TREE_MAP: 38 await dispatch(snapshot.refreshSelectedTreeMap(heapWorker)); 39 return; 40 41 case viewState.INDIVIDUALS: 42 await dispatch(snapshot.refreshIndividuals(heapWorker)); 43 return; 44 45 default: 46 assert(false, `Unexpected view state: ${getState().view.state}`); 47 } 48 }; 49 };