Skip to content

Commit e43057e

Browse files
committed
minor fixes
1 parent 7c1a839 commit e43057e

File tree

6 files changed

+26
-30
lines changed

6 files changed

+26
-30
lines changed

src/client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"publish": "npm --workspaces publish",
1313
"format": "npm --workspaces run format",
1414
"check:format": "npm --workspaces run check-format",
15-
"check:tests": "npm --workspaces check:tests",
15+
"check:tests": "npm --workspaces run check:tests",
1616
"check:types": "npm --workspaces run check:types"
1717
},
1818
"version": "1.0.0",

src/client/packages/app/src/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from "react";
22
import { render } from "react-dom";
3-
import { Layout, SimpleReactPyServer } from "@reactpy/client";
3+
import { Layout, SimpleReactPyClient } from "@reactpy/client";
44

55
export function mount(root: HTMLElement) {
6-
const server = new SimpleReactPyServer({
6+
const server = new SimpleReactPyClient({
77
serverApi: {
88
baseUrl: document.location.origin,
99
routePath: document.location.pathname,

src/client/packages/client/src/components.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ import {
2424
loadImportSource,
2525
ImportSourceBinding,
2626
} from "./reactpy-vdom";
27-
import { ReactPyServer } from "./reactpy-server";
27+
import { ReactPyClient } from "./reactpy-client";
2828

29-
const LayoutServer = createContext<ReactPyServer>(null as any);
29+
const LayoutServer = createContext<ReactPyClient>(null as any);
3030

31-
export function Layout(props: { server: ReactPyServer }): JSX.Element {
31+
export function Layout(props: { server: ReactPyClient }): JSX.Element {
3232
const currentModel: ReactPyVdom = useState({ tagName: "" })[0];
3333
const forceUpdate = useForceUpdate();
3434

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export * from "./components";
22
export * from "./messages";
3-
export * from "./reactpy-server";
3+
export * from "./reactpy-client";
44
export * from "./reactpy-vdom";

src/client/packages/client/src/reactpy-server.ts renamed to src/client/packages/client/src/reactpy-client.ts

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
import { OutgoingMessage, IncomingMessage } from "./messages";
22
import { ReactPyModule } from "./reactpy-vdom";
33

4-
export interface ReactPyServer {
4+
export interface ReactPyClient {
55
receiveMessage: <M extends IncomingMessage>(type: M["type"]) => Promise<M>;
66
sendMessage: (message: OutgoingMessage) => Promise<void>;
77
loadModule: (moduleName: string) => Promise<ReactPyModule>;
88
}
99

10-
export type StandardServerUrlProps = {
10+
type UrlProps = {
1111
baseUrl: string;
1212
routePath: string;
1313
queryString: string;
1414
};
1515

16-
export type StandardServerReconnectProps = {
16+
type ReconnectProps = {
1717
maxInterval?: number;
1818
maxRetries?: number;
1919
backoffRate?: number;
2020
intervalJitter?: number;
2121
};
2222

23-
export class SimpleReactPyServer implements ReactPyServer {
24-
private readonly urls: StandardServerUrls;
23+
export class SimpleReactPyClient implements ReactPyClient {
24+
private readonly urls: ServerUrls;
2525
private readonly handlers: {
2626
[key in IncomingMessage["type"]]?: ((message: any) => void)[];
2727
};
2828
private readonly socket: { current?: WebSocket };
2929

3030
constructor(props: {
31-
serverApi: StandardServerUrlProps;
32-
reconnectOptions?: StandardServerReconnectProps;
31+
serverApi: UrlProps;
32+
reconnectOptions?: ReconnectProps;
3333
}) {
3434
this.handlers = {};
3535

36-
this.urls = getStandardServerUrls(props.serverApi);
36+
this.urls = getServerUrls(props.serverApi);
3737

3838
this.socket = startReconnectingWebSocket({
3939
url: this.urls.stream,
@@ -82,25 +82,21 @@ export class SimpleReactPyServer implements ReactPyServer {
8282
}
8383
}
8484

85-
type StandardServerUrls = {
85+
type ServerUrls = {
8686
base: URL;
8787
stream: string;
8888
modules: string;
8989
assets: string;
9090
};
9191

92-
function getStandardServerUrls(
93-
props: StandardServerUrlProps,
94-
): StandardServerUrls {
92+
function getServerUrls(props: UrlProps): ServerUrls {
9593
const base = new URL(`${props.baseUrl || document.location.origin}/_reactpy`);
9694
const modules = `${base}/modules`;
9795
const assets = `${base}/assets`;
9896

99-
const wsProtocol = `ws${base.protocol === "https:" ? "s" : ""}`;
100-
const wsHost = `${base.host}:${base.port}`;
101-
const wsPath = `${props.routePath || ""}${props.routePath || ""}`;
102-
103-
const stream = `${wsProtocol}://${wsHost}${wsPath}`;
97+
const streamProtocol = `ws${base.protocol === "https:" ? "s" : ""}`;
98+
const streamPath = `${base.pathname}/stream${props.routePath || ""}`;
99+
const stream = `${streamProtocol}://${base.host}${streamPath}`;
104100

105101
return { base, modules, assets, stream };
106102
}
@@ -111,7 +107,7 @@ function startReconnectingWebSocket(
111107
onOpen: () => void;
112108
onMessage: (message: MessageEvent<any>) => void;
113109
onClose: () => void;
114-
} & StandardServerReconnectProps,
110+
} & ReconnectProps,
115111
) {
116112
const {
117113
maxInterval = 60000,

src/client/packages/client/src/reactpy-vdom.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React, { ComponentType, ReactNode } from "react";
2-
import { ReactPyServer } from "./reactpy-server";
2+
import { ReactPyClient } from "./reactpy-client";
33
// @ts-ignore
44
import serializeEvent from "event-to-object";
55
import { IncomingMessage, Message, OutgoingMessage } from "./messages";
66

77
export async function loadImportSource(
88
vdomImportSource: ReactPyVdomImportSource,
9-
server: ReactPyServer,
9+
server: ReactPyClient,
1010
): Promise<BindImportSource> {
1111
let module: ReactPyModule;
1212
if (vdomImportSource.sourceType === "URL") {
@@ -51,7 +51,7 @@ export async function loadImportSource(
5151
}
5252

5353
function createImportSourceElement(props: {
54-
server: ReactPyServer;
54+
server: ReactPyClient;
5555
module: ReactPyModule;
5656
binding: ReactPyModuleBinding;
5757
model: ReactPyVdom;
@@ -133,7 +133,7 @@ export function createChildren<Child>(
133133

134134
export function createAttributes(
135135
model: ReactPyVdom,
136-
server: ReactPyServer,
136+
server: ReactPyClient,
137137
): { [key: string]: any } {
138138
return Object.fromEntries(
139139
Object.entries({
@@ -151,7 +151,7 @@ export function createAttributes(
151151
}
152152

153153
function createEventHandler(
154-
{ sendMessage }: ReactPyServer,
154+
{ sendMessage }: ReactPyClient,
155155
name: string,
156156
{ target, preventDefault, stopPropagation }: ReactPyVdomEventHandler,
157157
): [string, () => void] {

0 commit comments

Comments
 (0)