Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
Tidy up pause reducer, remove logic for separating source trees, fix …
Browse files Browse the repository at this point in the history
…unit test problems.
  • Loading branch information
bhackett1024 authored and Jason Laster committed Dec 18, 2018
1 parent 4aedcd5 commit 02b6974
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 95 deletions.
4 changes: 2 additions & 2 deletions src/actions/pause/commands.js
Expand Up @@ -21,11 +21,11 @@ import type { Source } from "../../types";
import type { ThunkArgs } from "../types";
import type { Command } from "../../reducers/types";

export function selectThread(actor: string) {
export function selectThread(thread: string) {
return async ({ dispatch, client }: ThunkArgs) => {
return dispatch({
type: "SELECT_THREAD",
actor
thread
});
};
}
Expand Down
1 change: 1 addition & 0 deletions src/actions/pause/tests/pause.spec.js
Expand Up @@ -76,6 +76,7 @@ function createPauseInfo(
frameOpts = {}
) {
return {
thread: "FakeThread",
frames: [
makeFrame(
{ id: mockFrameId, sourceId: frameLocation.sourceId },
Expand Down
Expand Up @@ -13,6 +13,7 @@ Object {
"sourceMapURL": undefined,
"text": "undefined
",
"thread": "",
"url": "http://localhost:8000/examples/base.js:formatted",
}
`;
1 change: 1 addition & 0 deletions src/actions/sources/tests/select.spec.js
Expand Up @@ -36,6 +36,7 @@ describe("sources", () => {
await dispatch(actions.newSource(makeSource("foo1")));
await dispatch(
actions.paused({
thread: "FakeThread",
why: { type: "debuggerStatement" },
frames: [makeFrame({ id: "1", sourceId: "foo1" })]
})
Expand Down
1 change: 1 addition & 0 deletions src/actions/tests/ast.spec.js
Expand Up @@ -166,6 +166,7 @@ describe("ast", () => {

await dispatch(
actions.paused({
thread: "FakeThread",
why: { type: "debuggerStatement" },
frames: [makeFrame({ id: "1", sourceId: "scopes.js" })]
})
Expand Down
5 changes: 3 additions & 2 deletions src/actions/tests/expressions.spec.js
Expand Up @@ -5,15 +5,15 @@
import { actions, selectors, createStore } from "../../utils/test-head";

const mockThreadClient = {
evaluateInFrame: (script, frameId) =>
evaluateInFrame: (script, { frameId }) =>
new Promise((resolve, reject) => {
if (!frameId) {
resolve("bla");
} else {
resolve("boo");
}
}),
evaluateExpressions: (inputs, frameId) =>
evaluateExpressions: (inputs, { frameId }) =>
Promise.all(
inputs.map(
input =>
Expand Down Expand Up @@ -151,6 +151,7 @@ async function createFrames(dispatch) {

await dispatch(
actions.paused({
thread: "UnknownThread",
frames: [frame],
why: { type: "just because" }
})
Expand Down
1 change: 1 addition & 0 deletions src/actions/tests/preview.spec.js
Expand Up @@ -59,6 +59,7 @@ xdescribe("setPreview", () => {
await dispatch(actions.setSymbols(fileName));
await dispatch(
actions.paused({
thread: "FakeThread",
why: { type: "resumeLimit" },
frames: [
{ id: "frame1", location: { sourceId: fileName, line: 5, column: 1 } }
Expand Down
2 changes: 1 addition & 1 deletion src/actions/types/index.js
Expand Up @@ -139,7 +139,7 @@ export type DebugeeAction =
|}
| {|
+type: "SELECT_THREAD",
+actor: string
+thread: string
|};

export type {
Expand Down
5 changes: 1 addition & 4 deletions src/components/PrimaryPanes/SourcesTreeItem.js
Expand Up @@ -160,16 +160,13 @@ class SourceTreeItem extends Component<Props, State> {
renderItemName() {
const { item, depth } = this.props;

const name =
depth == 0 ? item.name.substr(item.name.indexOf(":") + 1) : item.name;

switch (item.name) {
case "ng://":
return "Angular";
case "webpack://":
return "Webpack";
default:
return `${name}`;
return `${item.name}`;
}
}

Expand Down
144 changes: 59 additions & 85 deletions src/reducers/pause.js
Expand Up @@ -72,12 +72,12 @@ export type PauseState = {
currentThread: string,
debuggeeUrl: string,
canRewind: boolean,
threads: Object
threads: { [string]: ThreadPauseState }
};

export const createAllPauseState = (): PauseState => ({
mainThread: "",
currentThread: "",
export const createPauseState = (): PauseState => ({
mainThread: "UnknownThread",
currentThread: "UnknownThread",
threads: {},
canRewind: false,
debuggeeUrl: ""
Expand Down Expand Up @@ -108,8 +108,14 @@ const createInitialPauseState = () => ({
skipPausing: prefs.skipPausing
});

function getThreadPauseState(state: PauseState, thread: string) {
// Thread state is lazily initialized so that we don't have to keep track of
// the current set of worker threads.
return state.threads[thread] || createInitialPauseState();
}

function update(
state: PauseState = createAllPauseState(),
state: PauseState = createPauseState(),
action: Action
): PauseState {
// Actions need to specify any thread they are operating on. These helpers
Expand All @@ -118,31 +124,25 @@ function update(
if (!action.thread) {
throw new Error(`Missing thread in action ${action.type}`);
}
return state.threads[action.thread] || createInitialPauseState();
return getThreadPauseState(state, action.thread);
};

const updateThreadState = threadState => {
const updateThreadState = newThreadState => {
if (!action.thread) {
throw new Error(`Missing thread in action ${action.type}`);
}
return {
...state,
threads: {
...state.threads,
[action.thread]: threadState
[action.thread]: { ...threadState(), ...newThreadState }
}
};
};

switch (action.type) {
case "SELECT_THREAD": {
const { actor } = action;

return {
...state,
currentThread: actor
};
}
case "SELECT_THREAD":
return { ...state, currentThread: action.thread };

case "PAUSED": {
const { thread, selectedFrameId, frames, loadedObjects, why } = action;
Expand All @@ -153,27 +153,24 @@ function update(
objectMap[obj.value.objectId] = obj;
});

const newState = {
...threadState(),
state = { ...state, currentThread: thread };
return updateThreadState({
isWaitingOnBreak: false,
selectedFrameId,
frames,
frameScopes: { ...resumedPauseState.frameScopes },
loadedObjects: objectMap,
why
};

state = { ...state, currentThread: thread };
return updateThreadState(newState);
});
}

case "MAP_FRAMES": {
const { selectedFrameId, frames } = action;
return updateThreadState({ ...threadState(), frames, selectedFrameId });
return updateThreadState({ frames, selectedFrameId });
}

case "ADD_EXTRA": {
return updateThreadState({ ...threadState(), extra: action.extra });
return updateThreadState({ extra: action.extra });
}

case "ADD_SCOPES": {
Expand All @@ -187,19 +184,17 @@ function update(
scope: value
}
};
const newState = {
...threadState(),

return updateThreadState({
frameScopes: {
...threadState().frameScopes,
generated
}
};

return updateThreadState(newState);
});
}

case "TRAVEL_TO":
return updateThreadState({ ...threadState(), ...action.data.paused });
return updateThreadState({ ...action.data.paused });

case "MAP_SCOPES": {
const { frame, status, value } = action;
Expand All @@ -217,46 +212,38 @@ function update(
...threadState().frameScopes.mappings,
[selectedFrameId]: value && value.mappings
};
const newState = {
...threadState(),

return updateThreadState({
frameScopes: {
...threadState().frameScopes,
original,
mappings
}
};

return updateThreadState(newState);
});
}

case "BREAK_ON_NEXT":
return updateThreadState({ ...threadState(), isWaitingOnBreak: true });
return updateThreadState({ isWaitingOnBreak: true });

case "SELECT_FRAME":
return updateThreadState({
...threadState(),
selectedFrameId: action.frame.id
});
return updateThreadState({ selectedFrameId: action.frame.id });

case "SET_POPUP_OBJECT_PROPERTIES": {
if (!action.properties) {
return state;
}

const newState = {
...threadState(),
return updateThreadState({
loadedObjects: {
...threadState().loadedObjects,
[action.objectId]: action.properties
}
};

return updateThreadState(newState);
});
}

case "CONNECT":
return {
...createAllPauseState(),
...createPauseState(),
mainThread: action.thread,
currentThread: action.thread,
debuggeeUrl: action.url,
Expand All @@ -272,63 +259,53 @@ function update(
// Preserving for the old debugger
prefs.ignoreCaughtExceptions = !shouldPauseOnCaughtExceptions;

const newState = {
...threadState(),
return updateThreadState({
shouldPauseOnExceptions,
shouldPauseOnCaughtExceptions
};

return updateThreadState(newState);
});
}

case "COMMAND": {
const newState =
action.status === "start"
? {
...threadState(),
...resumedPauseState,
command: action.command,
previousLocation: getPauseLocation(threadState(), action)
}
: { ...threadState(), command: null };

return updateThreadState(newState);
}
case "COMMAND":
if (action.status === "start") {
return updateThreadState({
...resumedPauseState,
command: action.command,
previousLocation: getPauseLocation(threadState(), action)
});
} else {
return updateThreadState({ command: null });
}

case "RESUME":
// Workaround for threads resuming before the initial connection.
if (!action.thread && !state.currentThread) {
return state;
}
return updateThreadState({ ...threadState(), resumedPauseState });
return updateThreadState(resumedPauseState);

case "EVALUATE_EXPRESSION": {
const newState = {
...threadState(),
case "EVALUATE_EXPRESSION":
return updateThreadState({
command: action.status === "start" ? "expression" : null
};
return updateThreadState(newState);
}
});

case "NAVIGATE": {
const newThreads = {};
newThreads[state.mainThread] = {
...state.threads[state.mainThread],
...resumedPauseState
};
case "NAVIGATE":
return {
...state,
currentThread: state.mainThread,
threads: newThreads,
threads: {
[state.mainThread]: {
...state.threads[state.mainThread],
...resumedPauseState
}
},
debuggeeUrl: action.url
};
}

case "TOGGLE_SKIP_PAUSING": {
const { skipPausing } = action;
prefs.skipPausing = skipPausing;

return updateThreadState({ ...threadState(), skipPausing });
return updateThreadState({ skipPausing });
}
}

Expand Down Expand Up @@ -367,9 +344,7 @@ function getPauseLocation(state, action) {
type OuterState = State;

function getCurrentPauseState(state: OuterState): ThreadPauseState {
return (
state.pause.threads[state.pause.currentThread] || createInitialPauseState()
);
return getThreadPauseState(state.pause, state.pause.currentThread);
}

export const getAllPopupObjectProperties = createSelector(
Expand Down Expand Up @@ -398,8 +373,7 @@ export function getCurrentThread(state: OuterState) {
}

export function threadIsPaused(state: OuterState, thread: string) {
const pauseState = state.pause.threads[thread] || createInitialPauseState();
return !!pauseState.frames;
return !!getThreadPauseState(state.pause, thread).frames;
}

export function isPaused(state: OuterState) {
Expand Down

0 comments on commit 02b6974

Please sign in to comment.