0.1.1 • Published 6 months ago

diffable-objects v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Installation

# NPM
$ npm install --save diffable-objects
# Yarn
$ yarn add diffable-objects
# PNPM
$ pnpm add diffable-objects
# Bun
$ bun add diffable-objects

Example

import { DurableObject } from "cloudflare:workers";
export { diffable, state } from "diffable-objects";

export class SampleObject extends DurableObject {
  // Within a durale object we can register a property to
  // have its values automatically tracked and persisted.
  #state = state(this.ctx, "state", { count: 0 });

  increment() {
    this.#state.count++;
  }
}

// Currently requires wrangler@next
export class DecoratorObject extends DurableObject {
  // You can also use decorators if you'd prefer a simpler
  // (but more magic) syntax.
  @diffable
  #state = { count: 0 };

  // Snapshot policies are configrable via an options object.
  @diffable({ snapshotPolicy: "every-change" })
  #stateWithOptions = { count: 0 };

  increment() {
    this.#state.count++;
    this.#stateWithOptions.count++;
  }
}

License

Distributed under the MIT License. See LICENSE for more information.

0.1.1

6 months ago

0.1.0

6 months ago

0.0.1

6 months ago

0.0.0

6 months ago