view.js (1986B)
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 { actions } = require("resource://devtools/client/memory/constants.js"); 8 const { 9 findSelectedSnapshot, 10 } = require("resource://devtools/client/memory/utils.js"); 11 const refresh = require("resource://devtools/client/memory/actions/refresh.js"); 12 13 /** 14 * Change the currently selected view. 15 * 16 * @param {viewState} view 17 */ 18 const changeView = (exports.changeView = function (view) { 19 return function ({ dispatch, getState }) { 20 dispatch({ 21 type: actions.CHANGE_VIEW, 22 newViewState: view, 23 oldDiffing: getState().diffing, 24 oldSelected: findSelectedSnapshot(getState()), 25 }); 26 }; 27 }); 28 29 /** 30 * Given that we are in the INDIVIDUALS view state, go back to the state we were 31 * in before. 32 */ 33 const popView = (exports.popView = function () { 34 return function ({ dispatch, getState }) { 35 const { previous } = getState().view; 36 assert(previous); 37 dispatch({ 38 type: actions.POP_VIEW, 39 previousView: previous, 40 }); 41 }; 42 }); 43 44 /** 45 * Change the currently selected view and ensure all our data is up to date from 46 * the heap worker. 47 * 48 * @param {viewState} view 49 * @param {HeapAnalysesClient} heapWorker 50 */ 51 exports.changeViewAndRefresh = function (view, heapWorker) { 52 return async function ({ dispatch }) { 53 dispatch(changeView(view)); 54 await dispatch(refresh.refresh(heapWorker)); 55 }; 56 }; 57 58 /** 59 * Given that we are in the INDIVIDUALS view state, go back to the state we were 60 * previously in and refresh our data. 61 * 62 * @param {HeapAnalysesClient} heapWorker 63 */ 64 exports.popViewAndRefresh = function (heapWorker) { 65 return async function ({ dispatch }) { 66 dispatch(popView()); 67 await dispatch(refresh.refresh(heapWorker)); 68 }; 69 };