forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbg.js
More file actions
65 lines (55 loc) · 1.65 KB
/
dbg.js
File metadata and controls
65 lines (55 loc) · 1.65 KB
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
import { bindActionCreators } from "redux";
import * as timings from "./timings";
import { prefs, features } from "./prefs";
function findSource(dbg, url) {
const sources = dbg.selectors.getSources();
const source = sources.find(s => (s.get("url") || "").includes(url));
if (!source) {
return;
}
return source.toJS();
}
function sendPacket(dbg, packet, callback) {
dbg.connection.tabConnection.debuggerClient
.request(packet)
.then(callback || console.log);
}
function evaluate(dbg, expression, callback) {
dbg.client.evaluate(expression).then(callback || console.log);
}
function bindSelectors(obj) {
return Object.keys(obj.selectors).reduce((bound, selector) => {
bound[selector] = (a, b, c) =>
obj.selectors[selector](obj.store.getState(), a, b, c);
return bound;
}, {});
}
function getCM() {
const cm = document.querySelector(".CodeMirror");
return cm && cm.CodeMirror;
}
export function setupHelper(obj) {
const selectors = bindSelectors(obj);
const actions = bindActionCreators(obj.actions, obj.store.dispatch);
const dbg = {
...obj,
selectors,
actions,
prefs,
features,
timings,
getCM,
helpers: {
findSource: url => findSource(dbg, url),
evaluate: (expression, cbk) => evaluate(dbg, expression, cbk),
sendPacket: (packet, cbk) => sendPacket(dbg, packet, cbk)
}
};
window.dbg = dbg;
console.group("Development Notes");
const baseUrl = "https://devtools-html.github.io/debugger.html";
const localDevelopmentUrl = `${baseUrl}/docs/dbg.html`;
console.log("Debugging Tips", localDevelopmentUrl);
console.log("dbg", window.dbg);
console.groupEnd();
}