@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.
- package/dist/ObservableList.d.ts +0 -12
- package/dist/ObservableList.js +3 -18
- package/dist/ObservableOptimisticReference.d.ts +1 -10
- package/dist/ObservableOptimisticReference.js +7 -24
- package/dist/ObservableReference.d.ts +0 -13
- package/dist/ObservableReference.js +3 -19
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/package.json +5 -5
package/dist/ObservableList.d.ts
CHANGED
|
@@ -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
|
package/dist/ObservableList.js
CHANGED
|
@@ -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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
|
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
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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 === '
|
|
22
|
-
|
|
12
|
+
if (prop === 'value' || prop === 'resolved' || prop === 'hasError' || prop === 'error') {
|
|
13
|
+
atom.reportObserved();
|
|
23
14
|
}
|
|
24
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
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.
|
|
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.
|
|
27
|
-
"@data-weave/datamanager": "~0.
|
|
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.
|
|
34
|
-
"@data-weave/datamanager": "~0.
|
|
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
|
},
|