Created
February 26, 2023 19:19
-
-
Save lmaccherone/49232a2f750987452d406bb079064350 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { TransactionalDOWrapperBase } from '@transformation-dev/cloudflare-do-utils' | |
export class OriginalGreeter { | |
async hydrate() { | |
if (this.hydrated) return | |
this.name = await this.state.storage.get('name') | |
this.greeting = await this.state.storage.get('greeting') | |
this.hydrated = true | |
} | |
constructor(state, env) { | |
this.state = state | |
this.env = env | |
this.hydrated = false | |
} | |
async fetch(request) { | |
await this.hydrate() | |
const url = new URL(request.url) | |
if (url.search === '') { | |
return new Response(this.greeting) | |
} else { | |
this.name = url.searchParams.get('name') | |
this.state.storage.put('name', this.name) | |
this.greeting = `${this.state.id.toString()}: ` | |
+ `Your name is ${this.name}. HELLO ${this.name.toUpperCase()}!` | |
this.state.storage.put('greeting', this.greeting) | |
return new Response(this.greeting) | |
} | |
} | |
} | |
export class Greeter extends TransactionalDOWrapperBase { | |
static TheClass = OriginalGreeter | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment