Skip to content

Commit e477492

Browse files
committed
fix docs
1 parent 04f6fa1 commit e477492

File tree

5 files changed

+41
-39
lines changed

5 files changed

+41
-39
lines changed

docs/source/_exts/interactive_widget.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,13 @@ def run(self):
3131
enableWidgetButton.setAttribute("class", "enable-widget-button")
3232
3333
enableWidgetButton.addEventListener("click", () => {{
34-
import("/client/src/layout.js").then((layout) => {{
34+
import("/client/index.js").then((module) => {{
3535
fadeOutAndThen(enableWidgetButton, () => {{
3636
mount.removeChild(enableWidgetButton);
3737
mount.setAttribute("class", "interactive widget-container");
38-
layout.mountLayoutWithWebSocket(
38+
module.mountLayoutWithWebSocket(
3939
mount,
4040
ws_proto + idom_url + "/stream?view_id={view_id}",
41-
"/client/web_modules",
4241
);
4342
}});
4443
}});

idom/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def install(packages: List[str]) -> None:
1818

1919

2020
@main.command()
21-
def restore() -> None:
22-
manage_client.build([], clean_build=True)
21+
def restore(clean_build: bool = True) -> None:
22+
manage_client.build([], clean_build=clean_build)
2323
return None
2424

2525

idom/client/app/index.html

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,9 @@
88
<body>
99
<div id="app"></div>
1010
<script type="module">
11-
import { mountLayout } from "idom-client-react";
11+
import { mountLayoutWithWebSocket } from "./index.js";
1212

13-
const uri = document.location.hostname + ":" + document.location.port;
14-
const url = (uri + document.location.pathname).split("/").slice(0, -1);
15-
url[url.length - 1] = "stream";
16-
const secure = document.location.protocol === "https:";
17-
18-
let protocol;
19-
if (secure) {
20-
protocol = "wss:";
21-
} else {
22-
protocol = "ws:";
23-
}
24-
25-
let endpoint = protocol + "//" + url.join("/") + window.location.search;
26-
27-
const ws = new WebSocket(endpoint);
28-
29-
function saveUpdateHook(update) {
30-
ws.onmessage = (event) => {
31-
const [pathPrefix, patch] = JSON.parse(event.data);
32-
update(pathPrefix, patch);
33-
};
34-
}
35-
36-
function sendCallback(event) {
37-
ws.send(JSON.stringify(event));
38-
}
39-
40-
mountLayout(
41-
document.getElementById("app"),
42-
saveUpdateHook,
43-
sendCallback,
44-
"../web_modules/"
45-
);
13+
mountLayoutWithWebSocket(document.getElementById("app"));
4614
</script>
4715
</body>
4816
</html>

idom/client/app/index.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { mountLayout } from "idom-client-react";
2+
3+
export function mountLayoutWithWebSocket(element, endpoint, importSourceURL) {
4+
const ws = new WebSocket(endpoint || defaultWebSocketEndpoint());
5+
6+
function saveUpdateHook(update) {
7+
ws.onmessage = (event) => {
8+
const [pathPrefix, patch] = JSON.parse(event.data);
9+
update(pathPrefix, patch);
10+
};
11+
}
12+
13+
function sendCallback(event) {
14+
ws.send(JSON.stringify(event));
15+
}
16+
17+
mountLayout(element, saveUpdateHook, sendCallback, importSourceURL || "./");
18+
}
19+
20+
function defaultWebSocketEndpoint() {
21+
const uri = document.location.hostname + ":" + document.location.port;
22+
const url = (uri + document.location.pathname).split("/").slice(0, -1);
23+
url[url.length - 1] = "stream";
24+
const secure = document.location.protocol === "https:";
25+
26+
let protocol;
27+
if (secure) {
28+
protocol = "wss:";
29+
} else {
30+
protocol = "ws:";
31+
}
32+
33+
return protocol + "//" + url.join("/") + window.location.search;
34+
}

idom/client/app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"description": "A client application for IDOM implemented in React",
44
"version": "0.1.0",
55
"author": "Ryan Morshead",
6+
"main": "index.js",
67
"license": "MIT",
78
"repository": {
89
"type": "git",

0 commit comments

Comments
 (0)