Skip to content

Commit

Permalink
rename: webSocketRemote 'fns' to 'remote'
Browse files Browse the repository at this point in the history
  • Loading branch information
chase-moskal committed Nov 3, 2024
1 parent fd2d1bb commit 3fbdfa3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<Serverside>(options)

// GOOD new way
const {remote: serverside} = await webSocketRemote<Serverside>(options)
```

logging and error handling has been revised and greatly improved.
- 🔶 simplified RemoteError constructor to just take a message like ordinary Error
Expand Down
5 changes: 4 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<Serverside>({
const {remote: serverside} = await webSocketRemote<Serverside>({
url: "http://localhost:8000",
getLocalEndpoint: serverside => endpoint(
makeClientside(() => serverside)
),
onClosed: () => {
console.log("web socket closed")
},
})

const result = await serverside.now()
Expand Down
6 changes: 3 additions & 3 deletions s/transports/websocket/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ export async function webSocketRemote<F extends Fns>(
onError,
})

const fns = remote<F>(socketry.remoteEndpoint, params)
const r = remote<F>(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}
})
}

2 changes: 1 addition & 1 deletion s/transports/websocket/examples/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {exampleClientsideApi, ExampleServersideFns} from "./apis.js"
let calls = 0
let rememberCall = () => calls++

const {socket, fns: serverside} = await webSocketRemote<ExampleServersideFns>({
const {socket, remote: serverside} = await webSocketRemote<ExampleServersideFns>({
url: "http://localhost:8000",
getLocalEndpoint: fns => endpoint(exampleClientsideApi(fns, rememberCall)),
onClose: () => console.error("web socket remote disconnected"),
Expand Down

0 comments on commit 3fbdfa3

Please sign in to comment.