@data-weave/datamanager-mobx 0.6.3 → 0.7.0

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,4 +1,3 @@
1
1
  import { LiveList } from '@data-weave/datamanager';
2
- export type ObservableList<T> = LiveList<T>;
3
2
  export declare const ObservableList: <T>(sourceList: LiveList<T>) => LiveList<T>;
4
3
  //# sourceMappingURL=ObservableList.d.ts.map
@@ -4,14 +4,14 @@ exports.ObservableList = void 0;
4
4
  const mobx_1 = require("mobx");
5
5
  const ObservableList = (sourceList) => {
6
6
  const atom = (0, mobx_1.createAtom)('ObservableList', () => sourceList.resolve(), () => sourceList.unsubscribe());
7
+ sourceList.registerOnChangeListener(() => {
8
+ atom.reportChanged();
9
+ });
7
10
  return new Proxy(sourceList, {
8
11
  get(target, prop, receiver) {
9
12
  if (prop === 'values' || prop === 'resolved' || prop === 'hasError' || prop === 'error') {
10
13
  atom.reportObserved();
11
14
  }
12
- if (prop === 'onValuesChange') {
13
- atom.reportChanged();
14
- }
15
15
  return Reflect.get(target, prop, receiver);
16
16
  },
17
17
  });
@@ -1,12 +1,3 @@
1
1
  import { LiveReference, OptimisticReference } from '@data-weave/datamanager';
2
- export type ObservableOptimisticReference<T extends object> = OptimisticReference<T>;
3
- /**
4
- * Wraps a `LiveReference<T>` with optimistic patch support and MobX
5
- * reactivity. Source-value reactivity is provided by `ObservableReference`;
6
- * a separate atom owned by this factory tracks `_patch` mutations made via
7
- * `applyOptimistic` / `clearOptimistic` so that MobX reactions observing
8
- * `value` (or `hasPendingOptimistic`) re-run when the optimistic overlay
9
- * changes.
10
- */
11
- export declare const ObservableOptimisticReference: <T extends object>(source: LiveReference<T>) => OptimisticReference<T>;
2
+ export declare const ObservableOptimisticReference: <T>(sourceReference: LiveReference<T>) => OptimisticReference<T>;
12
3
  //# sourceMappingURL=ObservableOptimisticReference.d.ts.map
@@ -3,33 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ObservableOptimisticReference = void 0;
4
4
  const datamanager_1 = require("@data-weave/datamanager");
5
5
  const mobx_1 = require("mobx");
6
- const ObservableReference_1 = require("./ObservableReference");
7
- /**
8
- * Wraps a `LiveReference<T>` with optimistic patch support and MobX
9
- * reactivity. Source-value reactivity is provided by `ObservableReference`;
10
- * a separate atom owned by this factory tracks `_patch` mutations made via
11
- * `applyOptimistic` / `clearOptimistic` so that MobX reactions observing
12
- * `value` (or `hasPendingOptimistic`) re-run when the optimistic overlay
13
- * changes.
14
- */
15
- const ObservableOptimisticReference = (source) => {
16
- const observableSource = (0, ObservableReference_1.ObservableReference)(source);
17
- const optimistic = new datamanager_1.OptimisticReference(observableSource);
18
- const patchAtom = (0, mobx_1.createAtom)('ObservableOptimisticReference');
6
+ const ObservableOptimisticReference = (sourceReference) => {
7
+ const optimistic = new datamanager_1.OptimisticReference(sourceReference);
8
+ const atom = (0, mobx_1.createAtom)('ObservableOptimisticLiveReference', () => sourceReference.resolve(), () => sourceReference.unsubscribe());
9
+ optimistic.registerOnChangeListener(() => atom.reportChanged());
19
10
  return new Proxy(optimistic, {
20
11
  get(target, prop, receiver) {
21
- if (prop === 'value' || prop === 'hasPendingOptimistic') {
22
- patchAtom.reportObserved();
12
+ if (prop === 'value' || prop === 'resolved' || prop === 'hasError' || prop === 'error') {
13
+ atom.reportObserved();
23
14
  }
24
- const value = Reflect.get(target, prop, receiver);
25
- if (prop === 'applyOptimistic' || prop === 'clearOptimistic') {
26
- return (...args) => {
27
- const result = value.apply(target, args);
28
- patchAtom.reportChanged();
29
- return result;
30
- };
31
- }
32
- return value;
15
+ return Reflect.get(target, prop, receiver);
33
16
  },
34
17
  });
35
18
  };
@@ -1,4 +1,3 @@
1
1
  import { LiveReference } from '@data-weave/datamanager';
2
- export type ObservableReference<T> = LiveReference<T>;
3
2
  export declare const ObservableReference: <T>(sourceReference: LiveReference<T>) => LiveReference<T>;
4
3
  //# sourceMappingURL=ObservableReference.d.ts.map
@@ -2,23 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ObservableReference = void 0;
4
4
  const mobx_1 = require("mobx");
5
- const PATCHED = Symbol('@data-weave/observableReference.patched');
6
5
  const ObservableReference = (sourceReference) => {
7
6
  const atom = (0, mobx_1.createAtom)('ObservableReference', () => sourceReference.resolve(), () => sourceReference.unsubscribe());
8
- // FirestoreReference (and any LiveReference) calls `this.onUpdate(...)` on
9
- // the bare instance from inside its snapshot callback, which then calls
10
- // `this.onValueChange()` on the bare instance too. The Proxy's get trap
11
- // never sees that call, so we patch the bare method to also notify the
12
- // atom. Idempotent across multiple wraps via the PATCHED symbol guard.
13
- const tagged = sourceReference;
14
- if (!tagged[PATCHED]) {
15
- tagged[PATCHED] = true;
16
- const original = sourceReference.onValueChange.bind(sourceReference);
17
- sourceReference.onValueChange = () => {
18
- original();
19
- atom.reportChanged();
20
- };
21
- }
7
+ sourceReference.registerOnChangeListener(() => {
8
+ atom.reportChanged();
9
+ });
22
10
  return new Proxy(sourceReference, {
23
11
  get(target, prop, receiver) {
24
12
  if (prop === 'value' || prop === 'resolved' || prop === 'hasError' || prop === 'error') {
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  export * from '@data-weave/backend-firestore';
2
2
  export * from '@data-weave/datamanager';
3
3
  export * from './ObservableList';
4
- export * from './ObservableOptimisticReference';
5
4
  export * from './ObservableReference';
6
5
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -17,6 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("@data-weave/backend-firestore"), exports);
18
18
  __exportStar(require("@data-weave/datamanager"), exports);
19
19
  __exportStar(require("./ObservableList"), exports);
20
- __exportStar(require("./ObservableOptimisticReference"), exports);
21
20
  __exportStar(require("./ObservableReference"), exports);
22
21
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@data-weave/datamanager-mobx",
3
- "version": "0.6.3",
3
+ "version": "0.7.0",
4
4
  "author": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -23,15 +23,15 @@
23
23
  "registry": "https://registry.npmjs.org/"
24
24
  },
25
25
  "dependencies": {
26
- "@data-weave/backend-firestore": "~0.6.3",
27
- "@data-weave/datamanager": "~0.6.3"
26
+ "@data-weave/backend-firestore": "~0.7.0",
27
+ "@data-weave/datamanager": "~0.7.0"
28
28
  },
29
29
  "peerDependencies": {
30
30
  "mobx": ">=6.0.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@data-weave/backend-firestore": "~0.6.3",
34
- "@data-weave/datamanager": "~0.6.3",
33
+ "@data-weave/backend-firestore": "~0.7.0",
34
+ "@data-weave/datamanager": "~0.7.0",
35
35
  "mobx": "6.15.0",
36
36
  "typescript": "5.9.3"
37
37
  },