Skip to content

Commit c588a76

Browse files
committed
released v3.0.0-next.3 - switching to
1 parent 77b19d7 commit c588a76

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ npm install itty-durable@next
3737
import { IttyDurable } from 'itty-durable'
3838

3939
export class Counter extends IttyDurable {
40-
// this property will be persisted
41-
value = 20
40+
// anything in this.persisted will be automatically stored
41+
$persisted = {
42+
value = 0
43+
}
4244

4345
increment(by: number = 1) {
44-
this.value += by
46+
this.$persisted.value += by
4547

4648
return this.$props() // optionally return the props
4749
}
@@ -58,24 +60,23 @@ Under the hood, `IttyDurable` (which directy extends `DurableObject`) returns a
5860

5961
# API
6062

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:
6264

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.
6567

6668
```ts
6769
export class Counter extends IttyDurable {
68-
// this property will be persisted
69-
value = 20
70+
// this property will not be persisted
71+
foo = 'bar'
7072

71-
// but this will not
72-
$ = {
73-
history: [1,2,3]
73+
// but this will be
74+
$persisted = {
75+
value = 0
7476
}
7577

7678
increment(by: number = 1) {
77-
this.value += by
78-
this.$.history.push(by)
79+
this.persisted.value += by
7980
}
8081
}
8182
```
@@ -134,7 +135,7 @@ The `$props()` method is used to simplify the extraction of your own properties,
134135
```ts
135136
export class Counter extends IttyDurable {
136137
value = 20
137-
foo = 'bar'
138+
foo = 'bar'
138139

139140
increment(by: number = 1) {
140141
this.value += by

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "itty-durable",
33
"description": "Easier to use Durable Objects.",
4-
"version": "3.0.0-next.2",
4+
"version": "3.0.0-next.3",
55
"main": "./index.js",
66
"module": "./index.mjs",
77
"types": "./index.d.ts",

src/IttyDurable.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class IttyDurable extends DurableObject {
2222
#persistLoaded: undefined | true
2323

2424
// persisted attributes
25-
persisted: any = {}
25+
$persisted: any = {}
2626

2727
// default store
2828
$store: DurableStore = {
@@ -74,7 +74,7 @@ export class IttyDurable extends DurableObject {
7474
// add a new timer, saving props to store when triggered
7575
this.#persistTimer = setTimeout(
7676
() => {
77-
this.$store.put.call(this, this.persisted)
77+
this.$store.put.call(this, this.$persisted)
7878
},
7979
delay
8080
)

0 commit comments

Comments
 (0)