1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
/* 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/>. */
// @flow
import {
getSourceActor,
getSourceActorBreakableLines,
getSourceActorBreakpointColumns,
type SourceActorId,
type SourceActor,
} from "../reducers/source-actors";
import {
memoizeableAction,
type MemoizedAction,
} from "../utils/memoizableAction";
import { PROMISE } from "./utils/middleware/promise";
import type { ThunkArgs } from "./types";
import type { Context } from "../utils/context";
export function insertSourceActors(items: Array<SourceActor>) {
return function({ dispatch }: ThunkArgs) {
dispatch({
type: "INSERT_SOURCE_ACTORS",
items,
});
};
}
export function removeSourceActor(item: SourceActor) {
return removeSourceActors([item]);
}
export function removeSourceActors(items: Array<SourceActor>) {
return function({ dispatch }: ThunkArgs) {
dispatch({ type: "REMOVE_SOURCE_ACTORS", items });
};
}
export const loadSourceActorBreakpointColumns: MemoizedAction<
{| id: SourceActorId, line: number, cx: Context |},
Array<number>
> = memoizeableAction("loadSourceActorBreakpointColumns", {
createKey: ({ id, line }) => `${id}:${line}`,
getValue: ({ id, line }, { getState }) =>
getSourceActorBreakpointColumns(getState(), id, line),
action: async ({ id, line }, { dispatch, getState, client }) => {
await dispatch({
type: "SET_SOURCE_ACTOR_BREAKPOINT_COLUMNS",
sourceId: id,
line,
[PROMISE]: (async () => {
const positions = await client.getSourceActorBreakpointPositions(
getSourceActor(getState(), id),
{
start: { line, column: 0 },
end: { line: line + 1, column: 0 },
}
);
return positions[line] || [];
})(),
});
},
});
export const loadSourceActorBreakableLines: MemoizedAction<
{| id: SourceActorId, cx: Context |},
Array<number>
> = memoizeableAction("loadSourceActorBreakableLines", {
createKey: args => args.id,
getValue: ({ id }, { getState }) =>
getSourceActorBreakableLines(getState(), id),
action: async ({ id }, { dispatch, getState, client }) => {
await dispatch({
type: "SET_SOURCE_ACTOR_BREAKABLE_LINES",
sourceId: id,
[PROMISE]: client.getSourceActorBreakableLines(
getSourceActor(getState(), id)
),
});
},
});
|