From 3fbdfa3575ca7ec115d5a875f86ef340a042f4c0 Mon Sep 17 00:00:00 2001 From: Chase Moskal Date: Sun, 3 Nov 2024 14:03:00 -0800 Subject: [PATCH] rename: webSocketRemote 'fns' to 'remote' --- changelog.md | 8 ++++++++ readme.md | 5 ++++- s/transports/websocket/client.ts | 6 +++--- s/transports/websocket/examples/client.ts | 2 +- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/changelog.md b/changelog.md index c3693ac..158f7e6 100644 --- a/changelog.md +++ b/changelog.md @@ -12,6 +12,14 @@ changes and improvements - 🍏 added new export `RandomUserEmojis` - 🟥 require `onClose` in `webSocketRemote` +- 🟥 in webSocketRemote, rename `fns` to `remote` + ```ts + // BAD old way + const {fns: serverside} = await webSocketRemote(options) + + // GOOD new way + const {remote: serverside} = await webSocketRemote(options) + ``` logging and error handling has been revised and greatly improved. - 🔶 simplified RemoteError constructor to just take a message like ordinary Error diff --git a/readme.md b/readme.md index 5db3191..8fe3c4f 100644 --- a/readme.md +++ b/readme.md @@ -232,11 +232,14 @@ maybe this project is my life's work, actually... import {webSocketRemote, Api} from "renraku" import {Serverside, makeClientside} from "./apis.js" - const [serverside, socket] = await webSocketRemote({ + const {remote: serverside} = await webSocketRemote({ url: "http://localhost:8000", getLocalEndpoint: serverside => endpoint( makeClientside(() => serverside) ), + onClosed: () => { + console.log("web socket closed") + }, }) const result = await serverside.now() diff --git a/s/transports/websocket/client.ts b/s/transports/websocket/client.ts index a2bc4ea..0b9e9e2 100644 --- a/s/transports/websocket/client.ts +++ b/s/transports/websocket/client.ts @@ -39,16 +39,16 @@ export async function webSocketRemote( onError, }) - const fns = remote(socketry.remoteEndpoint, params) + const r = remote(socketry.remoteEndpoint, params) socket.onclose = () => onClose() socket.onmessage = event => socketry.receive( - getLocalEndpoint(fns as F), + getLocalEndpoint(r as F), event, ) await ready - return {socket, fns} + return {socket, remote: r} }) } diff --git a/s/transports/websocket/examples/client.ts b/s/transports/websocket/examples/client.ts index c1a21eb..599128b 100644 --- a/s/transports/websocket/examples/client.ts +++ b/s/transports/websocket/examples/client.ts @@ -6,7 +6,7 @@ import {exampleClientsideApi, ExampleServersideFns} from "./apis.js" let calls = 0 let rememberCall = () => calls++ -const {socket, fns: serverside} = await webSocketRemote({ +const {socket, remote: serverside} = await webSocketRemote({ url: "http://localhost:8000", getLocalEndpoint: fns => endpoint(exampleClientsideApi(fns, rememberCall)), onClose: () => console.error("web socket remote disconnected"),