Skip to content

Commit 2398754

Browse files
committed
chore: update readme
1 parent 28ad93d commit 2398754

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

README.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,61 @@
88
<a href="https://www.npmjs.com/package/diffable-objects">
99
<img src="https://img.shields.io/npm/v/diffable-objects?style=for-the-badge" alt="downloads" height="24">
1010
</a>
11-
<a href="https://www.npmjs.com/package/diffable-objects">
11+
<a href="https://github.com/zebp/diffable-objects/actions">
1212
<img src="https://img.shields.io/github/actions/workflow/status/zebp/diffable-objects/ci.yaml?branch=main&style=for-the-badge" alt="npm version" height="24">
1313
</a>
1414
<a href="https://github.com/zebp/diffable-objects">
1515
<img src="https://img.shields.io/badge/license-MIT-green?style=for-the-badge" alt="MIT license" height="24">
1616
</a>
1717
</p>
1818

19+
## Installation
20+
21+
```
22+
# NPM
23+
$ npm install --save diffable-objects
24+
# Yarn
25+
$ yarn add diffable-objects
26+
# PNPM
27+
$ pnpm add diffable-objects
28+
# Bun
29+
$ bun add diffable-objects
30+
```
31+
32+
## Example
33+
34+
```typescript
35+
import { DurableObject } from "cloudflare:workers";
36+
export { diffable, state } from "diffable-objects";
37+
38+
export class SampleObject extends DurableObject {
39+
// Within a durale object we can register a property to
40+
// have its values automatically tracked and persisted.
41+
#state = state(this.ctx, "state", { count: 0 });
42+
43+
increment() {
44+
this.#state.count++;
45+
}
46+
}
47+
48+
// Currently requires wrangler@next
49+
export class DecoratorObject extends DurableObject {
50+
// You can also use decorators if you'd prefer a simpler
51+
// (but more magic) syntax.
52+
@diffable
53+
#state = { count: 0 };
54+
55+
// Snapshot policies are configrable via an options object.
56+
@diffable({ snapshotPolicy: "every-change" })
57+
#stateWithOptions = { count: 0 };
58+
59+
increment() {
60+
this.#state.count++;
61+
this.#stateWithOptions.count++;
62+
}
63+
}
64+
```
65+
1966
## License
2067

2168
Distributed under the MIT License. See [LICENSE](LICENSE) for more information.

0 commit comments

Comments
 (0)