Skip to content

Commit d425d5a

Browse files
authored
MY_DURABLE_OBJECT => MY_DURABLE_OBJECT_NAMESPACE
It is confusing to say that the binding name is `MY_DURABLE_OBJECT` — singular — and then call methods on it in order to....get a single Durable Objects instance. I don't think this creates the correct mental model, makes it seem like `MY_DURABLE_OBJECT` is a single durable object, instead of what it is — a namepaces of Durable Objects — plural.
1 parent 89f73a6 commit d425d5a

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/content/docs/durable-objects/get-started.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ To communicate with a Durable Object, the Worker's fetch handler should look lik
128128
```ts
129129
export default {
130130
async fetch(request, env, ctx): Promise<Response> {
131-
const id:DurableObjectId = env.MY_DURABLE_OBJECT.idFromName(new URL(request.url).pathname);
131+
const id:DurableObjectId = env.MY_DURABLE_OBJECT_NAMESPACE.idFromName(new URL(request.url).pathname);
132132

133-
const stub = env.MY_DURABLE_OBJECT.get(id);
133+
const stub = env.MY_DURABLE_OBJECT_NAMESPACE.get(id);
134134

135135
const greeting = await stub.sayHello();
136136

@@ -144,7 +144,7 @@ In the code above, you have:
144144

145145
1. Exported your Worker's main event handlers, such as the `fetch()` handler for receiving HTTP requests.
146146
2. Passed `env` into the `fetch()` handler. Bindings are delivered as a property of the environment object passed as the second parameter when an event handler or class constructor is invoked. By calling the `idFromName()` function on the binding, you use a string-derived object ID. You can also ask the system to [generate random unique IDs](/durable-objects/api/namespace/#newuniqueid). System-generated unique IDs have better performance characteristics, but require you to store the ID somewhere to access the Object again later.
147-
3. Derived an object ID from the URL path. `MY_DURABLE_OBJECT.idFromName()` always returns the same ID when given the same string as input (and called on the same class), but never the same ID for two different strings (or for different classes). In this case, you are creating a new object for each unique path.
147+
3. Derived an object ID from the URL path. `MY_DURABLE_OBJECT_NAMESPACE.idFromName()` always returns the same ID when given the same string as input (and called on the same class), but never the same ID for two different strings (or for different classes). In this case, you are creating a new object for each unique path.
148148
4. Constructed the stub for the Durable Object using the ID. A stub is a client object used to send messages to the Durable Object.
149149
5. Called a Durable Object by invoking a RPC method, `sayHello()`, on the Durable Object, which returns a `Hello, World!` string greeting.
150150
6. Received an HTTP response back to the client by constructing a HTTP Response with `return new Response()`.
@@ -153,13 +153,13 @@ Refer to [Access a Durable Object from a Worker](/durable-objects/best-practices
153153

154154
## 4. Configure Durable Object bindings
155155

156-
[Bindings](/workers/runtime-apis/bindings/) allow your Workers to interact with resources on the Cloudflare developer platform. The Durable Object bindings in your Worker project's [Wrangler configuration file](/workers/wrangler/configuration/) will include a binding name (for this guide, use `MY_DURABLE_OBJECT`) and the class name (`MyDurableObject`).
156+
[Bindings](/workers/runtime-apis/bindings/) allow your Workers to interact with resources on the Cloudflare developer platform. The Durable Object bindings in your Worker project's [Wrangler configuration file](/workers/wrangler/configuration/) will include a binding name (for this guide, use `MY_DURABLE_OBJECT_NAMESPACE`) and the class name (`MyDurableObject`).
157157

158158
<WranglerConfig>
159159

160160
```toml
161161
[[durable_objects.bindings]]
162-
name = "MY_DURABLE_OBJECT"
162+
name = "MY_DURABLE_OBJECT_NAMESPACE"
163163
class_name = "MyDurableObject"
164164
```
165165

@@ -235,9 +235,9 @@ export class MyDurableObject extends DurableObject<Env> {
235235
}
236236
export default {
237237
async fetch(request, env, ctx):Promise<Response> {
238-
const id:DurableObjectId = env.MY_DURABLE_OBJECT.idFromName(new URL(request.url).pathname);
238+
const id:DurableObjectId = env.MY_DURABLE_OBJECT_NAMESPACE.idFromName(new URL(request.url).pathname);
239239

240-
const stub = env.MY_DURABLE_OBJECT.get(id);
240+
const stub = env.MY_DURABLE_OBJECT_NAMESPACE.get(id);
241241

242242
const greeting = await stub.sayHello();
243243

0 commit comments

Comments
 (0)