|
1 | | -import React, { useMemo, useState } from 'react' |
| 1 | +import { useMemo, useState } from 'react' |
2 | 2 | import { newHttpBatchRpcSession } from '@cloudflare/jsrpc' |
| 3 | +import type { Api } from '../../../src/worker' |
3 | 4 |
|
4 | 5 | type Result = { |
5 | 6 | posts: number |
@@ -55,7 +56,7 @@ export function App() { |
55 | 56 | const t0 = performance.now() |
56 | 57 | wrapFetch.setOrigin(t0) |
57 | 58 | const calls: CallEvent[] = [] |
58 | | - const api = newHttpBatchRpcSession('/api') |
| 59 | + const api = newHttpBatchRpcSession<Api>('/api') |
59 | 60 | const userStart = 0; calls.push({ label: 'authenticate', start: userStart, end: NaN }) |
60 | 61 | const user = api.authenticate('cookie-123') |
61 | 62 | user.then(() => { calls.find(c => c.label==='authenticate')!.end = performance.now() - t0 }) |
@@ -83,19 +84,19 @@ export function App() { |
83 | 84 | const t0 = performance.now() |
84 | 85 | wrapFetch.setOrigin(t0) |
85 | 86 | const calls: CallEvent[] = [] |
86 | | - const api1 = newHttpBatchRpcSession('/api') |
| 87 | + const api1 = newHttpBatchRpcSession<Api>('/api') |
87 | 88 | const aStart = 0; calls.push({ label: 'authenticate', start: aStart, end: NaN }) |
88 | 89 | const uPromise = api1.authenticate('cookie-123') |
89 | 90 | uPromise.then(() => { calls.find(c => c.label==='authenticate')!.end = performance.now() - t0 }) |
90 | 91 | const u = await uPromise |
91 | 92 |
|
92 | | - const api2 = newHttpBatchRpcSession('/api') |
| 93 | + const api2 = newHttpBatchRpcSession<Api>('/api') |
93 | 94 | const pStart = performance.now() - t0; calls.push({ label: 'getUserProfile', start: pStart, end: NaN }) |
94 | 95 | const pPromise = api2.getUserProfile(u.id) |
95 | 96 | pPromise.then(() => { calls.find(c => c.label==='getUserProfile')!.end = performance.now() - t0 }) |
96 | 97 | const p = await pPromise |
97 | 98 |
|
98 | | - const api3 = newHttpBatchRpcSession('/api') |
| 99 | + const api3 = newHttpBatchRpcSession<Api>('/api') |
99 | 100 | const nStart = performance.now() - t0; calls.push({ label: 'getNotifications', start: nStart, end: NaN }) |
100 | 101 | const nPromise = api3.getNotifications(u.id) |
101 | 102 | nPromise.then(() => { calls.find(c => c.label==='getNotifications')!.end = performance.now() - t0 }) |
|
0 commit comments