Skip to content

Commit

Permalink
merged
Browse files Browse the repository at this point in the history
  • Loading branch information
kwhitley committed May 1, 2024
1 parent bcc0aa4 commit f5b35f5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
13 changes: 12 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,16 @@
"vitest": "^1.5.0",
"yarn-release": "^1.10.6"
},
"exports": {}
"exports": {
"./IttyDurable": {
"import": "./IttyDurable.mjs",
"require": "./IttyDurable.js",
"types": "./IttyDurable.d.ts"
},
"./withDurables": {
"import": "./withDurables.mjs",
"require": "./withDurables.js",
"types": "./withDurables.d.ts"
}
}
}
15 changes: 10 additions & 5 deletions src/IttyDurable.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { DurableObject } from 'cloudflare:workers'

class IttyDurable extends DurableObject {
persisted
#persistTimer
export class IttyDurable extends DurableObject {
// private attributes
#persistTimer: any
#persistDelay = 5000
#persistLoaded
#persistLoaded: undefined | true

// public attributes
persisted: undefined | true

constructor(...args: any) {
// @ts-ignore
super(...args)

return new Proxy(this, {
// @ts-ignore
get: (obj, prop, receiver, target = obj[prop]) =>
// @ts-ignore
(typeof target == 'function' && this.persist(prop))
Expand All @@ -23,7 +28,7 @@ class IttyDurable extends DurableObject {
return this.#persistLoaded = true
}

persist(methodName) {
persist() {
if (!this.persisted) return

clearTimeout(this.#persistTimer)
Expand Down

0 comments on commit f5b35f5

Please sign in to comment.