Skip to content

Commit e47eb93

Browse files
committed
Added refresh periodic polling (GraphiQL support)
1 parent ad4a7ef commit e47eb93

1 file changed

Lines changed: 28 additions & 33 deletions

File tree

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,33 @@
1-
(function(JSON) {
2-
const parse = JSON.parse;
3-
const fastDebug = document.getElementById("fastDebug");
1+
const refresh = (function () {
2+
function getCookie(name) {
3+
const parts = `; ${document.cookie}`.split(`; ${name}=`);
4+
if (parts.length === 2) return parts.pop().split(";").shift();
5+
}
6+
let lastCookie = getCookie("dtRefresh");
7+
const fastDebug = document.getElementById("fastDebug");
48

5-
function getCookie(name) {
6-
const parts = `; ${document.cookie}`.split(`; ${name}=`);
7-
if (parts.length === 2) return parts.pop().split(';').shift();
8-
}
9-
function deleteCookie(name) {
10-
document.cookie = `${name}=; path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT;`;
11-
}
12-
JSON.parse = function(text) {
13-
const data = parse(text);
14-
const cookie = getCookie("dtRefresh");
9+
return function () {
10+
const dtCookie = getCookie("dtRefresh");
1511

16-
if (!cookie) return data;
12+
if (dtCookie && dtCookie !== lastCookie) {
13+
lastCookie = dtCookie;
14+
const toolbar = JSON.parse(decodeURIComponent(lastCookie));
1715

18-
deleteCookie("dtRefresh");
19-
const toolbar = parse(decodeURIComponent(cookie));
16+
Object.entries(toolbar.panels).map(([id, subtitle]) => {
17+
document.getElementById(`fastdt-${id}`).querySelector("small").textContent = subtitle;
18+
});
19+
fastDebug.querySelectorAll(".fastDebugPanelContent").forEach(function (e) {
20+
e.querySelector(".fastdt-scroll").innerHTML = "";
2021

21-
Object.entries(toolbar.panels).map(([id, subtitle]) => {
22-
document
23-
.getElementById(`fastdt-${id}`)
24-
.querySelector("small").textContent = subtitle;
25-
});
26-
fastDebug.querySelectorAll('.fastDebugPanelContent').forEach(function (e) {
27-
e.querySelector(".fastdt-scroll").innerHTML = "";
28-
29-
if (e.querySelector(".fastdt-loader") === null) {
30-
const loader = document.createElement("div");
31-
loader.className = "fastdt-loader";
32-
e.prepend(loader);
33-
}
34-
});
35-
fastDebug.setAttribute("data-store-id", toolbar.storeId);
36-
return data;
22+
if (e.querySelector(".fastdt-loader") === null) {
23+
const loader = document.createElement("div");
24+
loader.className = "fastdt-loader";
25+
e.prepend(loader);
26+
}
27+
});
28+
fastDebug.setAttribute("data-store-id", toolbar.storeId);
3729
}
38-
})(JSON);
30+
};
31+
})();
32+
33+
window.setInterval(refresh, 100);

0 commit comments

Comments
 (0)