@data-weave/datamanager-mobx 0.6.4 → 0.7.1

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,15 +1,3 @@
1
1
  import { LiveList } from '@data-weave/datamanager';
2
- /**
3
- * Wraps a `LiveList<T>` so that MobX reactions observing `values`,
4
- * `resolved`, `hasError`, or `error` re-run whenever the underlying source
5
- * publishes a new snapshot. The atom drives `resolve` / `unsubscribe` via
6
- * `onBecomeObserved` / `onBecomeUnobserved`, and a one-time bridge installed
7
- * on the bare `onValuesChange` method propagates source updates to every
8
- * wrapping atom (since `FirestoreList` and other `LiveList` subclasses call
9
- * `this.onValuesChange()` on the bare instance, bypassing this proxy's get
10
- * trap). Multiple wraps of the same source are supported: each wrap registers
11
- * its own atom and all of them are notified on every snapshot.
12
- */
13
- export type ObservableList<T> = LiveList<T>;
14
2
  export declare const ObservableList: <T>(sourceList: LiveList<T>) => LiveList<T>;
15
3
  //# sourceMappingURL=ObservableList.d.ts.map
@@ -2,26 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ObservableList = void 0;
4
4
  const mobx_1 = require("mobx");
5
- const observingAtoms = Symbol('@data-weave/observableList.observingAtoms');
6
5
  const ObservableList = (sourceList) => {
7
6
  const atom = (0, mobx_1.createAtom)('ObservableList', () => sourceList.resolve(), () => sourceList.unsubscribe());
8
- // FirestoreList (and any LiveList) calls `this.onValuesChange()` on the
9
- // bare instance from inside its snapshot callback (via `onUpdate` /
10
- // `onUpdateAll` / `onError`). The Proxy's get trap never sees that call,
11
- // so we install (once per source) a bridge on the bare method that fans
12
- // each call out to every registered atom.
13
- const bridged = sourceList;
14
- if (!bridged[observingAtoms]) {
15
- const atoms = [];
16
- bridged[observingAtoms] = atoms;
17
- const original = sourceList.onValuesChange.bind(sourceList);
18
- sourceList.onValuesChange = () => {
19
- original();
20
- for (const a of atoms)
21
- a.reportChanged();
22
- };
23
- }
24
- bridged[observingAtoms].push(atom);
7
+ sourceList.registerOnChangeListener(() => {
8
+ atom.reportChanged();
9
+ });
25
10
  return new Proxy(sourceList, {
26
11
  get(target, prop, receiver) {
27
12
  if (prop === 'values' || prop === 'resolved' || prop === 'hasError' || prop === 'error') {
@@ -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,16 +1,3 @@
1
1
  import { LiveReference } from '@data-weave/datamanager';
2
- /**
3
- * Wraps a `LiveReference<T>` so that MobX reactions observing `value`,
4
- * `resolved`, `hasError`, or `error` re-run whenever the underlying source
5
- * publishes a new value. The atom drives `resolve` / `unsubscribe` via
6
- * `onBecomeObserved` / `onBecomeUnobserved`, and a one-time bridge installed
7
- * on the bare `onValueChange` method propagates source updates to every
8
- * wrapping atom (since `FirestoreReference` and other `LiveReference`
9
- * subclasses call `this.onValueChange()` on the bare instance, bypassing
10
- * this proxy's get trap). Multiple wraps of the same source are supported:
11
- * each wrap registers its own atom and all of them are notified on every
12
- * publish.
13
- */
14
- export type ObservableReference<T> = LiveReference<T>;
15
2
  export declare const ObservableReference: <T>(sourceReference: LiveReference<T>) => LiveReference<T>;
16
3
  //# sourceMappingURL=ObservableReference.d.ts.map
@@ -2,27 +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 observingAtoms = Symbol('@data-weave/observableReference.observingAtoms');
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(...)`
9
- // on the bare instance from inside its snapshot callback, which then
10
- // calls `this.onValueChange()` on the bare instance too. The Proxy's
11
- // get trap never sees that call, so we install (once per source) a
12
- // bridge on the bare method that fans each call out to every
13
- // registered atom.
14
- const bridged = sourceReference;
15
- if (!bridged[observingAtoms]) {
16
- const atoms = [];
17
- bridged[observingAtoms] = atoms;
18
- const original = sourceReference.onValueChange.bind(sourceReference);
19
- sourceReference.onValueChange = () => {
20
- original();
21
- for (const a of atoms)
22
- a.reportChanged();
23
- };
24
- }
25
- bridged[observingAtoms].push(atom);
7
+ sourceReference.registerOnChangeListener(() => {
8
+ atom.reportChanged();
9
+ });
26
10
  return new Proxy(sourceReference, {
27
11
  get(target, prop, receiver) {
28
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.4",
3
+ "version": "0.7.1",
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.4",
27
- "@data-weave/datamanager": "~0.6.4"
26
+ "@data-weave/backend-firestore": "~0.7.1",
27
+ "@data-weave/datamanager": "~0.7.1"
28
28
  },
29
29
  "peerDependencies": {
30
30
  "mobx": ">=6.0.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@data-weave/backend-firestore": "~0.6.4",
34
- "@data-weave/datamanager": "~0.6.4",
33
+ "@data-weave/backend-firestore": "~0.7.1",
34
+ "@data-weave/datamanager": "~0.7.1",
35
35
  "mobx": "6.15.0",
36
36
  "typescript": "5.9.3"
37
37
  },