diff options
Diffstat (limited to 'devtools/client/debugger/src/actions/pause/fetchScopes.js')
-rw-r--r-- | devtools/client/debugger/src/actions/pause/fetchScopes.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/devtools/client/debugger/src/actions/pause/fetchScopes.js b/devtools/client/debugger/src/actions/pause/fetchScopes.js new file mode 100644 index 0000000000..1de472d1ed --- /dev/null +++ b/devtools/client/debugger/src/actions/pause/fetchScopes.js @@ -0,0 +1,37 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */ + +import { + getGeneratedFrameScope, + getOriginalFrameScope, +} from "../../selectors/index"; +import { mapScopes } from "./mapScopes"; +import { generateInlinePreview } from "./inlinePreview"; +import { PROMISE } from "../utils/middleware/promise"; + +export function fetchScopes(selectedFrame) { + return async function ({ dispatch, getState, client }) { + // See if we already fetched the scopes. + // We may have pause on multiple thread and re-select a paused thread + // for which we already fetched the scopes. + // Ignore pending scopes as the previous action may have been cancelled + // by context assertions. + let scopes = getGeneratedFrameScope(getState(), selectedFrame); + if (!scopes?.scope) { + scopes = dispatch({ + type: "ADD_SCOPES", + selectedFrame, + [PROMISE]: client.getFrameScopes(selectedFrame), + }); + + scopes.then(() => { + dispatch(generateInlinePreview(selectedFrame)); + }); + } + + if (!getOriginalFrameScope(getState(), selectedFrame)) { + await dispatch(mapScopes(selectedFrame, scopes)); + } + }; +} |