@dabble/patches 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,4 @@
1
+ import { type Unsubscriber } from '../event-signal.js';
1
2
  import type { JSONPatch } from '../json-patch/JSONPatch.js';
2
3
  import type { Change, PatchesSnapshot } from '../types.js';
3
4
  /**
@@ -29,12 +30,16 @@ export declare class PatchesDoc<T extends object = object> {
29
30
  get id(): string | null;
30
31
  /** Current local state (committed + sending + pending). */
31
32
  get state(): T;
33
+ /** Alias for state. */
34
+ get value(): T;
32
35
  /** Last committed revision number from the server. */
33
36
  get committedRev(): number;
34
37
  /** Are there changes currently awaiting server confirmation? */
35
38
  get isSending(): boolean;
36
39
  /** Are there local changes that haven't been sent yet? */
37
40
  get hasPending(): boolean;
41
+ /** Subscribe to be notified whenever value changes. */
42
+ subscribe(onUpdate: (newValue: T) => void): Unsubscriber;
38
43
  /**
39
44
  * Exports the document state for persistence.
40
45
  * NOTE: Any changes currently marked as `sending` are included in the
@@ -37,6 +37,10 @@ export class PatchesDoc {
37
37
  get state() {
38
38
  return this._state;
39
39
  }
40
+ /** Alias for state. */
41
+ get value() {
42
+ return this._state;
43
+ }
40
44
  /** Last committed revision number from the server. */
41
45
  get committedRev() {
42
46
  return this._committedRev;
@@ -49,6 +53,12 @@ export class PatchesDoc {
49
53
  get hasPending() {
50
54
  return this._pendingChanges.length > 0;
51
55
  }
56
+ /** Subscribe to be notified whenever value changes. */
57
+ subscribe(onUpdate) {
58
+ const unsub = this.onUpdate(onUpdate);
59
+ onUpdate(this._state);
60
+ return unsub;
61
+ }
52
62
  /**
53
63
  * Exports the document state for persistence.
54
64
  * NOTE: Any changes currently marked as `sending` are included in the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dabble/patches",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "Immutable JSON Patch implementation based on RFC 6902 supporting operational transformation and last-writer-wins",
5
5
  "author": "Jacob Wright <jacwright@gmail.com>",
6
6
  "bugs": {