Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/batch-pipelining/server-node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const PROFILES = new Map([
]);

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

Expand Down
10 changes: 3 additions & 7 deletions examples/worker-react/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Cloudflare Workers + React Example

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.
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.

Prerequisites

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

2) Install and build the React app (Vite aliases `@cloudflare/jsrpc` to the local `dist`):
2) Install and build the React app (Vite aliases `capnweb` to the local `dist`):
cd examples/worker-react/web
npm install
npm run build
Expand All @@ -40,8 +40,4 @@ Tuning delays
- `DELAY_PROFILE_MS` (default 120)
- `DELAY_NOTIFS_MS` (default 120)
- `SIMULATED_RTT_MS` per direction (default 120)
- `SIMULATED_RTT_JITTER_MS` per direction (default 40)

Notes

- 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.
- `SIMULATED_RTT_JITTER_MS` per direction (default 40)
7 changes: 3 additions & 4 deletions examples/worker-react/src/worker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Use local build output so this example runs without publishing to npm.
import { newWorkersRpcResponse, RpcTarget } from '../../../dist/index.js';
import { newWorkersRpcResponse, RpcTarget } from 'capnweb';

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

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

class Api extends RpcTarget {
export class Api extends RpcTarget {
constructor(private env: Env) { super(); }

async authenticate(sessionToken: string) {
Expand Down
2 changes: 1 addition & 1 deletion examples/worker-react/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>JSRPC Workers + React Example</title>
<title>Cap'n Web Cloudflare Workers + React Example</title>
</head>
<body>
<div id="root"></div>
Expand Down
4 changes: 2 additions & 2 deletions examples/worker-react/web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/worker-react/web/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "jsrpc-react-web",
"name": "capnweb-react-web",
"private": true,
"version": "0.0.0",
"type": "module",
Expand Down
4 changes: 2 additions & 2 deletions examples/worker-react/web/src/main/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useMemo, useState } from 'react'
import { newHttpBatchRpcSession } from '@cloudflare/jsrpc'
import { newHttpBatchRpcSession } from 'capnweb'
import type { Api } from '../../../src/worker'

type Result = {
Expand Down Expand Up @@ -127,7 +127,7 @@ export function App() {

return (
<div style={{ fontFamily: 'system-ui, sans-serif', padding: 24, lineHeight: 1.5 }}>
<h1>JSRPC: Workers + React</h1>
<h1>Cap'n Web: Cloudflare Workers + React</h1>
<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>
<p>This demo calls the Worker API in two ways:</p>
<ul>
Expand Down
2 changes: 1 addition & 1 deletion examples/worker-react/web/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"strict": true,
"baseUrl": ".",
"paths": {
"@cloudflare/jsrpc": ["../../../dist/index.d.ts"]
"capnweb": ["../../../dist/index.d.ts"]
}
},
"include": ["src"]
Expand Down
6 changes: 3 additions & 3 deletions examples/worker-react/web/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { defineConfig } from 'vite'
import path from 'node:path'

// Map '@cloudflare/jsrpc' to the repo's local dist build so we can run
// the example without publishing to npm.
// Map 'capnweb' to the repo's local dist build so
// we can run using the local build.
export default defineConfig({
resolve: {
alias: {
'@cloudflare/jsrpc': path.resolve(__dirname, '../../../dist/index.js'),
'capnweb': path.resolve(__dirname, '../../../dist/index.js'),
},
},
// Ensure modern output so top-level await is allowed (library uses it).
Expand Down
2 changes: 1 addition & 1 deletion examples/worker-react/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name = "jsrpc-react-example"
name = "capnweb-react-example"
main = "src/worker.ts"
compatibility_date = "2024-09-01"

Expand Down