Skip to content

Commit 89a706f

Browse files
authored
fix(worker-react): jsrpc -> capnweb (#35)
* fix(worker-react): jsrpc -> capnweb * fix(worker-react): import server type * fix: last remnants of jsrpc
1 parent d21e4ca commit 89a706f

File tree

10 files changed

+18
-23
lines changed

10 files changed

+18
-23
lines changed

examples/batch-pipelining/server-node.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const PROFILES = new Map([
2323
]);
2424

2525
const NOTIFICATIONS = new Map([
26-
['u_1', ['Welcome to jsrpc!', 'You have 2 new followers']],
26+
['u_1', ['Welcome to Cap\'n Web!', 'You have 2 new followers']],
2727
['u_2', ['New feature: pipelining!', 'Security tips for your account']],
2828
]);
2929

examples/worker-react/README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Cloudflare Workers + React Example
22

3-
This example shows a Cloudflare Worker exposing a JSRPC API and a React app calling it from the browser. It demonstrates batching + promise pipelining vs sequential requests, with timing and request counts.
3+
This example shows a Cloudflare Worker exposing a Cap'n Web API and a React app calling it from the browser. It demonstrates batching + promise pipelining vs sequential requests, with timing and request counts.
44

55
Prerequisites
66

@@ -21,7 +21,7 @@ Run locally
2121
1) Build the library at repo root (the example uses the local dist build):
2222
npm run build
2323

24-
2) Install and build the React app (Vite aliases `@cloudflare/jsrpc` to the local `dist`):
24+
2) Install and build the React app (Vite aliases `capnweb` to the local `dist`):
2525
cd examples/worker-react/web
2626
npm install
2727
npm run build
@@ -40,8 +40,4 @@ Tuning delays
4040
- `DELAY_PROFILE_MS` (default 120)
4141
- `DELAY_NOTIFS_MS` (default 120)
4242
- `SIMULATED_RTT_MS` per direction (default 120)
43-
- `SIMULATED_RTT_JITTER_MS` per direction (default 40)
44-
45-
Notes
46-
47-
- The frontend imports `@cloudflare/jsrpc`. If trying this example before publish, you can `npm link` the built package into the `web` app or adjust imports to point at a local path.
43+
- `SIMULATED_RTT_JITTER_MS` per direction (default 40)

examples/worker-react/src/worker.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// Use local build output so this example runs without publishing to npm.
2-
import { newWorkersRpcResponse, RpcTarget } from '../../../dist/index.js';
1+
import { newWorkersRpcResponse, RpcTarget } from 'capnweb';
32

43
type Env = {
54
DELAY_AUTH_MS?: string;
@@ -23,11 +22,11 @@ const PROFILES = new Map([
2322
]);
2423

2524
const NOTIFICATIONS = new Map([
26-
['u_1', ['Welcome to jsrpc!', 'You have 2 new followers']],
25+
['u_1', ['Welcome to Cap\'n Web!', 'You have 2 new followers']],
2726
['u_2', ['New feature: pipelining!', 'Security tips for your account']],
2827
]);
2928

30-
class Api extends RpcTarget {
29+
export class Api extends RpcTarget {
3130
constructor(private env: Env) { super(); }
3231

3332
async authenticate(sessionToken: string) {

examples/worker-react/web/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6-
<title>JSRPC Workers + React Example</title>
6+
<title>Cap'n Web Cloudflare Workers + React Example</title>
77
</head>
88
<body>
99
<div id="root"></div>

examples/worker-react/web/package-lock.json

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

examples/worker-react/web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "jsrpc-react-web",
2+
"name": "capnweb-react-web",
33
"private": true,
44
"version": "0.0.0",
55
"type": "module",

examples/worker-react/web/src/main/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useMemo, useState } from 'react'
2-
import { newHttpBatchRpcSession } from '@cloudflare/jsrpc'
2+
import { newHttpBatchRpcSession } from 'capnweb'
33
import type { Api } from '../../../src/worker'
44

55
type Result = {
@@ -127,7 +127,7 @@ export function App() {
127127

128128
return (
129129
<div style={{ fontFamily: 'system-ui, sans-serif', padding: 24, lineHeight: 1.5 }}>
130-
<h1>JSRPC: Workers + React</h1>
130+
<h1>Cap'n Web: Cloudflare Workers + React</h1>
131131
<div style={{ opacity: 0.8 }}>Network RTT is simulated on the server (configurable via SIMULATED_RTT_MS/SIMULATED_RTT_JITTER_MS in wrangler.toml).</div>
132132
<p>This demo calls the Worker API in two ways:</p>
133133
<ul>

examples/worker-react/web/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"strict": true,
1414
"baseUrl": ".",
1515
"paths": {
16-
"@cloudflare/jsrpc": ["../../../dist/index.d.ts"]
16+
"capnweb": ["../../../dist/index.d.ts"]
1717
}
1818
},
1919
"include": ["src"]

examples/worker-react/web/vite.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { defineConfig } from 'vite'
22
import path from 'node:path'
33

4-
// Map '@cloudflare/jsrpc' to the repo's local dist build so we can run
5-
// the example without publishing to npm.
4+
// Map 'capnweb' to the repo's local dist build so
5+
// we can run using the local build.
66
export default defineConfig({
77
resolve: {
88
alias: {
9-
'@cloudflare/jsrpc': path.resolve(__dirname, '../../../dist/index.js'),
9+
'capnweb': path.resolve(__dirname, '../../../dist/index.js'),
1010
},
1111
},
1212
// Ensure modern output so top-level await is allowed (library uses it).

examples/worker-react/wrangler.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name = "jsrpc-react-example"
1+
name = "capnweb-react-example"
22
main = "src/worker.ts"
33
compatibility_date = "2024-09-01"
44

0 commit comments

Comments
 (0)