sor4chi / hono-do

A wrapper of Cloudflare Workers's Durable Object for Hono.
https://www.npmjs.com/package/hono-do
MIT License
81 stars 2 forks source link

feat: define state #2

Closed sor4chi closed 1 year ago

sor4chi commented 1 year ago

This is a proposal PR to wrap storage state with react-like api.

The state is defined in such a way that storage, key, and initial value are defined, and thereafter getValue and setValue can be used in a type-safe manner.

const [getValue, setValue] = await defineState(state.storage, "value", 0);

await getValue() // 0
await setValue(1)
await getValue() // 1

await setValue((value) => value + 1) // 2
await getValue() // 2

await delValue()
await getValue() // 0
changeset-bot[bot] commented 1 year ago

🦋 Changeset detected

Latest commit: 510682ed425cfbec2e1089f16957ebef66a5e066

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages | Name | Type | | ----------------------------------------- | ----- | | hono-do | Minor | | hono-do-example-batcher | Patch | | hono-do-example-chat | Patch | | hono-do-example-counter-with-state-helper | Patch | | hono-do-example-counter | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR