@@ -52,7 +52,7 @@ import Bun from "/images/platforms/bun.svg";
52
52
</div >
53
53
</CardGroup >
54
54
55
- <div style = { { height: " 24px " }} />
55
+ <div style = { { height: " 16px " }} />
56
56
57
57
<CardGroup cols = { 4 } >
58
58
<Card title = " Durable, In-Memory State" icon = " floppy-disk" >
@@ -73,11 +73,11 @@ import Bun from "/images/platforms/bun.svg";
73
73
</Card >
74
74
</CardGroup >
75
75
76
- <div class = " text-center" >
77
- <h2 >Features</h2 >
78
- </div >
76
+ <div style = { { height: " 16px" }} />
79
77
80
- { " " }
78
+ <div class = " text-center text-white text-xl font-semibold not-prose mt-8 mb-4" >
79
+ Features
80
+ </div >
81
81
82
82
<CardGroup cols = { 3 } >
83
83
<Card
@@ -113,7 +113,7 @@ import Bun from "/images/platforms/bun.svg";
113
113
/>
114
114
</CardGroup >
115
115
116
- <div style = { { height: " 24px " }} />
116
+ <div style = { { height: " 128px " }} />
117
117
118
118
<div class = " text-center" >
119
119
<h2 >What makes ActorCore different?</h2 >
@@ -193,128 +193,129 @@ import Bun from "/images/platforms/bun.svg";
193
193
<p class = " text-center" >† = on supported platforms</p >
194
194
</div >
195
195
196
+ <div style = { { height: " 96px" }} />
196
197
197
198
## Quickstart
198
199
199
- <Steps >
200
- <Step title = " Install" >
201
- <CodeGroup >
202
- ``` sh npm
203
- npm add actor-core
200
+ <Steps >
201
+ <Step title = " Install" >
202
+ <CodeGroup >
203
+ ``` sh npm
204
+ npm add actor-core
205
+ ```
206
+
207
+ ``` sh pnpm
208
+ pnpm add actor-core
204
209
```
205
210
206
- ``` sh pnpm
207
- pnpm add actor-core
208
- ```
211
+ ``` sh yarn
212
+ yarn add actor-core
213
+ ```
209
214
210
- ``` sh yarn
211
- yarn add actor-core
212
- ```
215
+ ``` sh bun
216
+ bun add actor-core
217
+ ```
218
+ </CodeGroup >
219
+ </Step >
220
+ <Step title = " Create Actor" >
221
+ <CodeGroup >
213
222
214
- ``` sh bun
215
- bun add actor-core
216
- ```
217
- </CodeGroup >
218
- </Step >
219
- <Step title = " Create Actor" >
220
- <CodeGroup >
223
+ ``` typescript Actor (TypeScript)
224
+ import { Actor , type Rpc } from " actor-core" ;
221
225
222
- ``` typescript Actor (TypeScript)
223
- import { Actor , type Rpc } from " actor-core" ;
226
+ export interface State {
227
+ messages: { username: string ; message: string }[];
228
+ }
224
229
225
- export interface State {
226
- messages: { username: string ; message: string }[];
230
+ export default class ChatRoom extends Actor <State > {
231
+ // initialize this._state
232
+ _onInitialize() {
233
+ return { messages: [] };
227
234
}
228
235
229
- export default class ChatRoom extends Actor <State > {
230
- // initialize this._state
231
- _onInitialize() {
232
- return { messages: [] };
233
- }
236
+ // receive an remote procedure call from the client
237
+ sendMessage(rpc : Rpc <ChatRoom >, username : string , message : string ) {
238
+ // save message to persistent storage
239
+ this ._state .messages .push ({ username , message });
234
240
235
- // receive an remote procedure call from the client
236
- sendMessage(rpc : Rpc <ChatRoom >, username : string , message : string ) {
237
- // save message to persistent storage
238
- this ._state .messages .push ({ username , message });
239
-
240
- // broadcast message to all clients
241
- this ._broadcast (" newMessage" , username , message );
242
- }
241
+ // broadcast message to all clients
242
+ this ._broadcast (" newMessage" , username , message );
243
243
}
244
- ```
244
+ }
245
+ ```
245
246
246
- ``` javascript Actor (JavaScript)
247
- import { Actor } from " actor-core" ;
247
+ ``` javascript Actor (JavaScript)
248
+ import { Actor } from " actor-core" ;
248
249
249
- export default class ChatRoom extends Actor {
250
- // initialize this._state
251
- _onInitialize () {
252
- return { messages: [] };
253
- }
250
+ export default class ChatRoom extends Actor {
251
+ // initialize this._state
252
+ _onInitialize () {
253
+ return { messages: [] };
254
+ }
254
255
255
- // receive an remote procedure call from the client
256
- sendMessage (rpc , username , message ) {
257
- // save message to persistent storage
258
- this ._state .messages .push ({ username, message });
256
+ // receive an remote procedure call from the client
257
+ sendMessage (rpc , username , message ) {
258
+ // save message to persistent storage
259
+ this ._state .messages .push ({ username, message });
259
260
260
- // broadcast message to all clients
261
- this ._broadcast (" newMessage" , username, message);
262
- }
261
+ // broadcast message to all clients
262
+ this ._broadcast (" newMessage" , username, message);
263
263
}
264
- ```
264
+ }
265
+ ```
265
266
266
- </CodeGroup >
267
- </Step >
268
- <Step title = " Connect to Actor" >
269
- <CodeGroup >
267
+ </CodeGroup >
268
+ </Step >
269
+ <Step title = " Connect to Actor" >
270
+ <CodeGroup >
270
271
271
- ``` typescript Browser (TypeScript)
272
- import { Client } from " actor-core/client" ;
273
- import type ChatRoom from " ../src/chat-room.ts" ;
272
+ ``` typescript Browser (TypeScript)
273
+ import { Client } from " actor-core/client" ;
274
+ import type ChatRoom from " ../src/chat-room.ts" ;
274
275
275
- const client = new Client (/* manager endpoint */ );
276
+ const client = new Client (/* manager endpoint */ );
276
277
277
- // connect to chat room
278
- const chatRoom = await client .get <ChatRoom >({ name: " chat" });
278
+ // connect to chat room
279
+ const chatRoom = await client .get <ChatRoom >({ name: " chat" });
279
280
280
- // listen for new messages
281
- chatRoom .on (" newMessage" , (username : string , message : string ) =>
282
- console .log (` Message from ${username }: ${message } ` ),
283
- );
281
+ // listen for new messages
282
+ chatRoom .on (" newMessage" , (username : string , message : string ) =>
283
+ console .log (` Message from ${username }: ${message } ` ),
284
+ );
284
285
285
- // send message to room
286
- await chatRoom .sendMessage (" william" , " All the world's a stage." );
287
- ```
286
+ // send message to room
287
+ await chatRoom .sendMessage (" william" , " All the world's a stage." );
288
+ ```
288
289
289
- ``` javascript Browser (JavaScript)
290
- import { Client } from " actor-core/client" ;
290
+ ``` javascript Browser (JavaScript)
291
+ import { Client } from " actor-core/client" ;
291
292
292
- const client = new Client (/* manager endpoint */ );
293
+ const client = new Client (/* manager endpoint */ );
293
294
294
- // connect to chat room
295
- const chatRoom = await client .get ({ name: " chat" });
295
+ // connect to chat room
296
+ const chatRoom = await client .get ({ name: " chat" });
296
297
297
- // listen for new messages
298
- chatRoom .on (" newMessage" , (username , message ) =>
299
- console .log (` Message from ${ username} : ${ message} ` ),
300
- );
298
+ // listen for new messages
299
+ chatRoom .on (" newMessage" , (username , message ) =>
300
+ console .log (` Message from ${ username} : ${ message} ` ),
301
+ );
301
302
302
- // send message to room
303
- await chatRoom .sendMessage (" william" , " All the world's a stage." );
304
- ```
303
+ // send message to room
304
+ await chatRoom .sendMessage (" william" , " All the world's a stage." );
305
+ ```
305
306
306
- </CodeGroup >
307
- </Step >
308
- <Step title = " Deploy" >
309
- Deploy to your platform of choice:
307
+ </CodeGroup >
308
+ </Step >
309
+ <Step title = " Deploy" >
310
+ Deploy to your platform of choice:
310
311
311
- - [ Rivet] ( /platforms/rivet )
312
- - [ Cloudflare Workers] ( /platforms/cloudflare-workers )
313
- - [ Bun] ( /platforms/bun )
314
- - [ Node.js] ( /platforms/nodejs )
315
- </Step >
312
+ - [ Rivet] ( /platforms/rivet )
313
+ - [ Cloudflare Workers] ( /platforms/cloudflare-workers )
314
+ - [ Bun] ( /platforms/bun )
315
+ - [ Node.js] ( /platforms/nodejs )
316
+ </Step >
316
317
317
- </Steps >
318
+ </Steps >
318
319
319
320
## Community & Support
320
321
0 commit comments