Skip to content

Commit e197a2f

Browse files
refactor: remove unused websocket playground, replace with code example (#159)
1 parent 5f73a44 commit e197a2f

7 files changed

Lines changed: 37 additions & 199 deletions

File tree

package-lock.json

Lines changed: 1 addition & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
"react-router": "^7.13.2",
1212
"react-router-dom": "^7.13.2",
1313
"react-spinners": "^0.17.0",
14-
"reactstrap": "^9.2.3",
15-
"reconnecting-websocket": "^4.4.0"
14+
"reactstrap": "^9.2.3"
1615
},
1716
"scripts": {
1817
"build-script": "node build-scripts/main.mjs",

src/App.css

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,6 @@ p:last-child {
4141
font-size: 1.35rem;
4242
}
4343

44-
.editor-output h5 {
45-
font-size: 1.1rem;
46-
color: gray;
47-
text-align: center;
48-
padding-bottom: 0.5rem;
49-
border-bottom: 1px solid #b7b7b7;
50-
}
51-
52-
.editor-output pre {
53-
font-family: monospace;
54-
}
55-
5644
.inline-editor-frame {
5745
margin-top: 1em;
5846
margin-bottom: 1.5em;

src/App.jsx

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { useState, useEffect, useRef, useCallback } from 'react';
21
import './App.css';
32

43
import Home from "./page/Home";
@@ -12,64 +11,10 @@ import { Container, Navbar, Nav, NavItem, NavLink, Row } from 'reactstrap';
1211
import { Route, Routes } from "react-router";
1312
import { Link } from "react-router-dom";
1413

15-
import ReconnectingWebSocket from 'reconnecting-websocket';
1614
import Blog from "./page/Blog";
1715
import Internships from "./page/Internships";
1816

19-
const SocketAddress = 'wss://evaluator.flix.dev/ws';
20-
2117
function App() {
22-
const [connected, setConnected] = useState(false);
23-
const websocketRef = useRef(null);
24-
25-
useEffect(() => {
26-
console.log("Connecting to: " + SocketAddress);
27-
28-
let options = {
29-
connectionTimeout: 2500
30-
};
31-
32-
const ws = new ReconnectingWebSocket(SocketAddress, [], options);
33-
34-
ws.addEventListener("open", () => {
35-
console.log("Connected to: " + SocketAddress);
36-
setConnected(true);
37-
});
38-
ws.addEventListener("close", event => {
39-
console.log("Disconnected from: " + SocketAddress);
40-
console.log(event);
41-
setConnected(false);
42-
});
43-
ws.addEventListener("error", event => {
44-
console.log("Disconnected from: " + SocketAddress);
45-
console.log(event);
46-
setConnected(false);
47-
});
48-
49-
websocketRef.current = ws;
50-
51-
return () => {
52-
ws.close();
53-
};
54-
}, []);
55-
56-
const runProgram = useCallback((src, callback) => {
57-
if (!connected) {
58-
console.log("Not connected yet");
59-
return;
60-
}
61-
62-
websocketRef.current.onmessage = event => {
63-
console.log("Received reply from: " + SocketAddress);
64-
const data = JSON.parse(event.data);
65-
66-
console.log(data);
67-
callback(data);
68-
};
69-
70-
websocketRef.current.send(JSON.stringify({ src }));
71-
}, [connected]);
72-
7318
return (
7419
<Container className="page">
7520
<Navbar dark color="info" expand="md" className="menu shadow-sm mb-4">
@@ -114,7 +59,7 @@ function App() {
11459
</Navbar>
11560

11661
<Routes>
117-
<Route path="/" element={<Home flix={{ connected, run: runProgram }} />} />
62+
<Route path="/" element={<Home />} />
11863
<Route path="/get-started/" element={<GetStarted />} />
11964
<Route path="/vscode/" element={<VSCode />} />
12065
<Route path="/principles/" element={<Principles />} />

src/page/Home.jsx

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
Row,
1111
UncontrolledCarousel
1212
} from 'reactstrap';
13-
import Codebox from "../util/Codebox";
1413
import InlineEditor from "../util/InlineEditor";
1514

1615
const carousel = [
@@ -36,7 +35,7 @@ const carousel = [
3635
}
3736
];
3837

39-
function Home({ flix }) {
38+
function Home() {
4039
useEffect(() => {
4140
document.title = "The Flix Programming Language";
4241
}, []);
@@ -88,7 +87,39 @@ function Home({ flix }) {
8887
</p>
8988
</Col>
9089
<Col md="6">
91-
<Codebox flix={flix}/>
90+
<InlineEditor>{`/// Demonstrates composing multiple HTTP middleware
91+
/// via \`with\` clauses. Stacks base URL, default
92+
/// headers, retry, circuit breaker, and logging.
93+
/// Each \`with\` wraps the
94+
/// preceding block. The \`Http\` and \`Logger\` effects
95+
/// propagate to \`main\` and are handled automatically
96+
/// via their default handlers. Relative paths are
97+
/// resolved against the base URL; absolute URLs
98+
/// bypass it.
99+
def main(): Unit \\ { Clock, Http, Logger, IO } =
100+
let defaultHeaders = Map#{
101+
"Accept" => List#{"application/json"},
102+
"Authorization" => List#{"Bearer tok123"}
103+
};
104+
run {
105+
let urls = List#{"/api/users", "/api/posts"};
106+
foreach (url <- urls) {
107+
match Http.get(url) {
108+
case Ok(res) => println("\${url} -> \${status(res)}")
109+
case Err(err) => println("\${url} -> \${err}")
110+
}
111+
};
112+
match Http.get("https://notfound.flix.dev/") {
113+
case Ok(res) => println("notfound -> \${status(res)}")
114+
case Err(err) => println("notfound -> \${err}")
115+
}
116+
} with Http.withBaseUrl("https://flix.dev")
117+
with Http.withDefaultHeaders(defaultHeaders)
118+
with Http.withRetry(
119+
Retry.linear(maxRetries = 2, delay = milliseconds(100)))
120+
with Http.withCircuitBreaker(
121+
failureThreshold = 3, cooldown = seconds(5))
122+
with Http.withLogging`}</InlineEditor>
92123
</Col>
93124
</Row>
94125

src/util/Codebox.jsx

Lines changed: 0 additions & 92 deletions
This file was deleted.

src/util/Editor.jsx

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)