Skip to content

Commit 4ba1e70

Browse files
authored
Merge pull request #44 from mappum/consistent-style
Make style consistent in 'Using Durable Objects'
2 parents 4fd3a4a + 25ba1d3 commit 4ba1e70

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

products/workers/src/content/learning/using-durable-objects.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Durable Objects gain access to a [persistent storage API](/runtime-apis/durable-
7575
```js
7676

7777
export class DurableObjectExample {
78-
constructor(state, env){
78+
constructor(state, env) {
7979
this.storage = state.storage;
8080
}
8181

@@ -96,7 +96,7 @@ Each individual storage operation behaves like a database transaction. More comp
9696
```js
9797

9898
export class DurableObjectExample {
99-
constructor(state, env){
99+
constructor(state, env) {
100100
this.storage = state.storage;
101101
}
102102

@@ -106,13 +106,13 @@ export class DurableObjectExample {
106106
let newValue = await request.text();
107107
let changedValue = false;
108108
await this.storage.transaction(async txn => {
109-
let currentValue = await txn.get(key);
110-
if (currentValue != ifMatch && ifMatch != '*') {
111-
txn.rollback();
112-
return;
113-
}
114-
changedValue = true;
115-
await txn.put(key, newValue);
109+
let currentValue = await txn.get(key);
110+
if (currentValue != ifMatch && ifMatch != '*') {
111+
txn.rollback();
112+
return;
113+
}
114+
changedValue = true;
115+
await txn.put(key, newValue);
116116
});
117117
return new Response("Changed: " + changedValue);
118118
}
@@ -178,7 +178,7 @@ For the following example, we'll be using this Durable Object class:
178178
```js
179179
// durable-object-example.mjs
180180
export class DurableObjectExample {
181-
constructor(state, env){
181+
constructor(state, env) {
182182
this.state = state;
183183
}
184184

@@ -195,7 +195,7 @@ export class DurableObjectExample {
195195
// required for the script to be accepted by the API endpoint
196196
export default {
197197
async fetch(request, env) {
198-
return new Response("Hello World")
198+
return new Response("Hello World");
199199
}
200200
}
201201
```
@@ -310,20 +310,20 @@ When a Worker talks to a Durable Object, it does so through a "stub" object. The
310310
```js
311311

312312
addEventListener('fetch', event => {
313-
event.respondWith(handleRequest(event.request))
314-
})
313+
event.respondWith(handleRequest(event.request));
314+
});
315315

316316
async function handleRequest(request) {
317317
// Derive an object ID from the URL path. `EXAMPLE_CLASS.idFromName()`
318318
// always returns the same ID when given the same string as input (and
319319
// called on the same class), but never the same ID for two different
320320
// strings (or for different classes). So, in this case, we are creating
321321
// a new object for each unique path.
322-
let id = EXAMPLE_CLASS.idFromName(new URL(request.url).pathname)
322+
let id = EXAMPLE_CLASS.idFromName(new URL(request.url).pathname);
323323

324324
// Construct the stub for the Durable Object. A "stub" is a client object
325325
// used to send messages to the Durable Object.
326-
let stub = await EXAMPLE_CLASS.get(id)
326+
let stub = await EXAMPLE_CLASS.get(id);
327327

328328
// Forward the request to the Durable Object. Note that `stub.fetch()` has
329329
// the same signature as the global `fetch()` function, except that the
@@ -393,17 +393,17 @@ We've included complete example code for both the Worker and the Durable Object
393393

394394
export default {
395395
async fetch(request, env) {
396-
return await handleRequest(request, env)
396+
return await handleRequest(request, env);
397397
}
398398
}
399399

400400
async function handleRequest(request, env) {
401-
let id = env.Counter.idFromName("A")
402-
let obj = env.Counter.get(id)
403-
let resp = await obj.fetch(request.url)
404-
let count = await resp.text()
401+
let id = env.Counter.idFromName("A");
402+
let obj = env.Counter.get(id);
403+
let resp = await obj.fetch(request.url);
404+
let count = await resp.text();
405405

406-
return new Response("Durable Object 'A' count: " + count)
406+
return new Response("Durable Object 'A' count: " + count);
407407
}
408408

409409
// Durable Object

0 commit comments

Comments
 (0)