You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+15-14Lines changed: 15 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -37,11 +37,13 @@ npm install itty-durable@next
37
37
import { IttyDurable } from'itty-durable'
38
38
39
39
exportclassCounterextendsIttyDurable {
40
-
// this property will be persisted
41
-
value =20
40
+
// anything in this.persisted will be automatically stored
41
+
$persisted = {
42
+
value=0
43
+
}
42
44
43
45
increment(by:number=1) {
44
-
this.value+=by
46
+
this.$persisted.value+=by
45
47
46
48
returnthis.$props() // optionally return the props
47
49
}
@@ -58,24 +60,23 @@ Under the hood, `IttyDurable` (which directy extends `DurableObject`) returns a
58
60
59
61
# API
60
62
61
-
The API of `IttyDurable` is intentionally minimalist. In fact, we only expose a handful of properties/methods:
63
+
The API of `IttyDurable` is intentionally minimalist. In fact, we only expose a handful of properties/methods, each prefixed with a `$` for clarity/separation:
62
64
63
-
### `$` - memory/temp properties
64
-
The `$` property on your DO defaults to a blank object, and is designed to house any memory-only properties you want. This property, and all contents within it, is specifically excluded from storage writes.
65
+
### `$persisted` -
66
+
The `$persisted` property in your DO is automatically synced via the store (defaults to using DO internal storage using a single key). Anything you put in here will be saved. Anything outside will reside in memory only, resetting when the DO resets/sleeps.
65
67
66
68
```ts
67
69
exportclassCounterextendsIttyDurable {
68
-
// this property will be persisted
69
-
value=20
70
+
// this property will not be persisted
71
+
foo='bar'
70
72
71
-
// but this will not
72
-
$ = {
73
-
history: [1,2,3]
73
+
// but this will be
74
+
$persisted= {
75
+
value=0
74
76
}
75
77
76
78
increment(by:number=1) {
77
-
this.value+=by
78
-
this.$.history.push(by)
79
+
this.persisted.value+=by
79
80
}
80
81
}
81
82
```
@@ -134,7 +135,7 @@ The `$props()` method is used to simplify the extraction of your own properties,
0 commit comments