UNPKG

983 BJavaScriptView Raw
1// @ts-check
2// Allow access from GUI on another port
3document.domain = window.location.hostname;
4
5const codelift = (action, ...args) => {
6 window.top.postMessage(
7 {
8 source: "codelift",
9 payload: { action, args }
10 },
11 "*"
12 );
13};
14
15codelift("setPath", window.location.href.split(window.location.origin).pop());
16
17// Intercept history methods that don't have a listener
18["pushState", "replaceState"].forEach(method => {
19 const original = window.history[method];
20
21 window.history[method] = (...args) => {
22 original.apply(window.history, args);
23 codelift("syncPath");
24 };
25});
26
27window.addEventListener("popstate", () => codelift("syncPath"));
28
29// @ts-ignore
30if (module.hot) {
31 // @ts-ignore
32 module.hot.addStatusHandler(status => {
33 codelift("handleStatus", status);
34 });
35}
36
37module.exports = function register({ React, ReactDOM }) {
38 if (!window.React) {
39 window.React = React;
40 }
41
42 if (!window.ReactDOM) {
43 window.ReactDOM = ReactDOM;
44 }
45};