From c588a7689782f1bb930119e3ebdcd1b876c49009 Mon Sep 17 00:00:00 2001 From: Kevin Whitley Date: Fri, 14 Jun 2024 23:12:06 -0500 Subject: [PATCH] released v3.0.0-next.3 - switching to --- README.md | 29 +++++++++++++++-------------- package.json | 2 +- src/IttyDurable.ts | 4 ++-- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index c1aa401..6c8366c 100644 --- a/README.md +++ b/README.md @@ -37,11 +37,13 @@ npm install itty-durable@next import { IttyDurable } from 'itty-durable' export class Counter extends IttyDurable { - // this property will be persisted - value = 20 + // anything in this.persisted will be automatically stored + $persisted = { + value = 0 + } increment(by: number = 1) { - this.value += by + this.$persisted.value += by return this.$props() // optionally return the props } @@ -58,24 +60,23 @@ Under the hood, `IttyDurable` (which directy extends `DurableObject`) returns a # API -The API of `IttyDurable` is intentionally minimalist. In fact, we only expose a handful of properties/methods: +The API of `IttyDurable` is intentionally minimalist. In fact, we only expose a handful of properties/methods, each prefixed with a `$` for clarity/separation: -### `$` - memory/temp properties -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. +### `$persisted` - +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. ```ts export class Counter extends IttyDurable { - // this property will be persisted - value = 20 + // this property will not be persisted + foo = 'bar' - // but this will not - $ = { - history: [1,2,3] + // but this will be + $persisted = { + value = 0 } increment(by: number = 1) { - this.value += by - this.$.history.push(by) + this.persisted.value += by } } ``` @@ -134,7 +135,7 @@ The `$props()` method is used to simplify the extraction of your own properties, ```ts export class Counter extends IttyDurable { value = 20 - foo = 'bar' + foo = 'bar' increment(by: number = 1) { this.value += by diff --git a/package.json b/package.json index 1d316b3..79fae65 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "itty-durable", "description": "Easier to use Durable Objects.", - "version": "3.0.0-next.2", + "version": "3.0.0-next.3", "main": "./index.js", "module": "./index.mjs", "types": "./index.d.ts", diff --git a/src/IttyDurable.ts b/src/IttyDurable.ts index d6ea184..eb2549f 100644 --- a/src/IttyDurable.ts +++ b/src/IttyDurable.ts @@ -22,7 +22,7 @@ export class IttyDurable extends DurableObject { #persistLoaded: undefined | true // persisted attributes - persisted: any = {} + $persisted: any = {} // default store $store: DurableStore = { @@ -74,7 +74,7 @@ export class IttyDurable extends DurableObject { // add a new timer, saving props to store when triggered this.#persistTimer = setTimeout( () => { - this.$store.put.call(this, this.persisted) + this.$store.put.call(this, this.$persisted) }, delay )