Skip to content

Commit 2f1a370

Browse files
authored
[DO] Ensuring DO constructors call super if extends from DurableObject (#24956)
* Adding super to constructors * Removing redundant lines
1 parent 6923cf2 commit 2f1a370

File tree

4 files changed

+4
-7
lines changed

4 files changed

+4
-7
lines changed

src/content/docs/durable-objects/api/alarms.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const SECONDS = 1000;
9797

9898
export class AlarmExample extends DurableObject {
9999
constructor(ctx, env) {
100-
this.ctx = ctx;
100+
super(ctx, env);
101101
this.storage = ctx.storage;
102102
}
103103
async fetch(request) {

src/content/docs/durable-objects/examples/alarms-api.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const SECONDS = 10;
3030
// Durable Object
3131
export class Batcher extends DurableObject {
3232
constructor(state, env) {
33-
this.state = state;
33+
super(state, env);
3434
this.storage = state.storage;
3535
this.state.blockConcurrencyWhile(async () => {
3636
let vals = await this.storage.list({ reverse: true, limit: 1 });

src/content/docs/durable-objects/examples/durable-object-in-memory-state.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ async function handleRequest(request, env) {
3434
// Durable Object
3535
export class Location extends DurableObject {
3636
constructor(state, env) {
37-
this.state = state;
37+
super(state, env);
3838
// Upon construction, you do not have a location to provide.
3939
// This value will be updated as people access the Durable Object.
4040
// When the Durable Object is evicted from memory, this will be reset.

src/content/docs/durable-objects/examples/use-kv-from-durable-objects.mdx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,7 @@ export class YourDurableObject extends DurableObject {
7979
public state: DurableObjectState,
8080
env: Env,
8181
) {
82-
this.state = state;
83-
// Ensure you pass your bindings and environmental variables into
84-
// each Durable Object when it is initialized
85-
this.env = env;
82+
super(state, env);
8683
}
8784

8885
async fetch(request: Request) {

0 commit comments

Comments
 (0)