Skip to content

Commit a817cbd

Browse files
committed
move store into different file, make transports persistent
1 parent dd73d77 commit a817cbd

File tree

5 files changed

+43
-48
lines changed

5 files changed

+43
-48
lines changed

static/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
<script src="/baremux/index.js"></script>
5555
<script src="/scram/scramjet.controller.js"></script>
5656
<script src="config.js"></script>
57+
<script src="store.js"></script>
5758
</head>
5859

5960
<body>

static/playground.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
<script src="/baremux/index.js"></script>
5555
<script src="/scram/scramjet.controller.js"></script>
5656
<script src="config.js"></script>
57+
<script src="store.js"></script>
5758
</head>
5859

5960
<body>

static/playground.js

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,7 @@ const col = css`
2424
flex-direction: column;
2525
`;
2626

27-
const store = $store(
28-
{
29-
url: "https://google.com",
30-
wispurl:
31-
_CONFIG?.wispurl ||
32-
(location.protocol === "https:" ? "wss" : "ws") +
33-
"://" +
34-
location.host +
35-
"/wisp/",
36-
bareurl:
37-
_CONFIG?.bareurl ||
38-
(location.protocol === "https:" ? "https" : "http") +
39-
"://" +
40-
location.host +
41-
"/bare/",
42-
proxy: "",
43-
},
44-
{ ident: "settings", backing: "localstorage", autosave: "auto" }
45-
);
46-
connection.setTransport("/epoxy/index.mjs", [{ wisp: store.wispurl }]);
27+
connection.setTransport(store.transport, [{ wisp: store.wispurl }]);
4728

4829
function PlaygroundApp() {
4930
this.css = `

static/store.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const store = $store(
2+
{
3+
url: "https://google.com",
4+
wispurl:
5+
_CONFIG?.wispurl ||
6+
(location.protocol === "https:" ? "wss" : "ws") +
7+
"://" +
8+
location.host +
9+
"/wisp/",
10+
bareurl:
11+
_CONFIG?.bareurl ||
12+
(location.protocol === "https:" ? "https" : "http") +
13+
"://" +
14+
location.host +
15+
"/bare/",
16+
proxy: "",
17+
transport: "/epoxy/index.mjs",
18+
},
19+
{ ident: "settings", backing: "localstorage", autosave: "auto" }
20+
);
21+
self.store = store;

static/ui.js

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,7 @@ const col = css`
2727
flex-direction: column;
2828
`;
2929

30-
const store = $store(
31-
{
32-
url: "https://google.com",
33-
wispurl:
34-
_CONFIG?.wispurl ||
35-
(location.protocol === "https:" ? "wss" : "ws") +
36-
"://" +
37-
location.host +
38-
"/wisp/",
39-
bareurl:
40-
_CONFIG?.bareurl ||
41-
(location.protocol === "https:" ? "https" : "http") +
42-
"://" +
43-
location.host +
44-
"/bare/",
45-
proxy: "",
46-
},
47-
{ ident: "settings", backing: "localstorage", autosave: "auto" }
48-
);
49-
connection.setTransport("/epoxy/index.mjs", [{ wisp: store.wispurl }]);
30+
connection.setTransport(store.transport, [{ wisp: store.wispurl }]);
5031

5132
function Config() {
5233
this.css = `
@@ -102,12 +83,22 @@ function Config() {
10283
<dialog class="cfg" style="background-color: #121212; color: white; border-radius: 8px;">
10384
<div style="align-self: end">
10485
<div class=${[flex, "buttons"]}>
105-
<button on:click=${() => connection.setTransport("/baremod/index.mjs", [store.bareurl])}>use bare server 3</button>
106-
<button on:click=${() =>
86+
<button on:click=${() => {
87+
connection.setTransport("/baremod/index.mjs", [store.bareurl]);
88+
store.transport = "/baremod/index.mjs";
89+
}}>use bare server 3</button>
90+
<button on:click=${() => {
10791
connection.setTransport("/libcurl/index.mjs", [
10892
{ wisp: store.wispurl },
109-
])}>use libcurl.js</button>
110-
<button on:click=${() => connection.setTransport("/epoxy/index.mjs", [{ wisp: store.wispurl }])}>use epoxy</button>
93+
]);
94+
store.transport = "/libcurl/index.mjs";
95+
}}>use libcurl.js</button>
96+
<button on:click=${() => {
97+
connection.setTransport("/epoxy/index.mjs", [
98+
{ wisp: store.wispurl },
99+
]);
100+
store.transport = "/epoxy/index.mjs";
101+
}}>use epoxy</button>
111102
</div>
112103
</div>
113104
<div class=${[flex, col, "input_row"]}>
@@ -118,10 +109,10 @@ function Config() {
118109
<label for="bare_url_input">Bare URL:</label>
119110
<input id="bare_url_input" bind:value=${use(store.bareurl)} spellcheck="false"></input>
120111
</div>
121-
<div class=${[flex, "buttons", "centered"]}>
122-
<button on:click=${() => handleModalClose(this.root)}>close</button>
123-
</div>
124-
112+
<div>${use(store.transport)}</div>
113+
<div class=${[flex, "buttons", "centered"]}>
114+
<button on:click=${() => handleModalClose(this.root)}>close</button>
115+
</div>
125116
</dialog>
126117
`;
127118
}

0 commit comments

Comments
 (0)