Skip to content

Commit 220682d

Browse files
committed
no more mountLayoutWithWebSocket
also remove pre-mature header/body fields
1 parent 449d5c3 commit 220682d

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

idom/client/app/index.html

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

1313
const uri = document.location.hostname + ":" + document.location.port;
1414
const url = (uri + document.location.pathname).split("/").slice(0, -1);
@@ -24,9 +24,23 @@
2424

2525
let endpoint = protocol + "//" + url.join("/") + window.location.search;
2626

27-
mountLayoutWithWebSocket(
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(
2841
document.getElementById("app"),
29-
endpoint,
42+
saveUpdateHook,
43+
sendCallback,
3044
"../web_modules/"
3145
);
3246
</script>

idom/client/app/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@
2323
"react-dom": "^16.13.1"
2424
},
2525
"snowpack": {
26-
"install": ["htm", "react", "react-dom", "idom-client-react"],
26+
"install": [
27+
"htm",
28+
"react",
29+
"react-dom",
30+
"idom-client-react"
31+
],
2732
"installOptions": {
2833
"polyfillNode": true
2934
}

idom/server/sanic.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ async def sock_send(value: Any) -> None:
8484
await socket.send(json.dumps(value))
8585

8686
async def sock_recv() -> LayoutEvent:
87-
message = json.loads(await socket.recv())
88-
event = message["body"]["event"]
87+
event = json.loads(await socket.recv())
8988
return LayoutEvent(event["target"], event["data"])
9089

9190
element_params = {k: request.args.get(k) for k in request.args}

sys

Whitespace-only changes.

0 commit comments

Comments
 (0)