@data-weave/datamanager-mobx 0.6.3 → 0.6.4
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 +11 -0
- package/dist/ObservableList.js +18 -3
- package/dist/ObservableReference.d.ts +12 -0
- package/dist/ObservableReference.js +14 -10
- package/package.json +5 -5
package/dist/ObservableList.d.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
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
|
+
*/
|
|
2
13
|
export type ObservableList<T> = LiveList<T>;
|
|
3
14
|
export declare const ObservableList: <T>(sourceList: LiveList<T>) => LiveList<T>;
|
|
4
15
|
//# sourceMappingURL=ObservableList.d.ts.map
|
package/dist/ObservableList.js
CHANGED
|
@@ -2,16 +2,31 @@
|
|
|
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');
|
|
5
6
|
const ObservableList = (sourceList) => {
|
|
6
7
|
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
25
|
return new Proxy(sourceList, {
|
|
8
26
|
get(target, prop, receiver) {
|
|
9
27
|
if (prop === 'values' || prop === 'resolved' || prop === 'hasError' || prop === 'error') {
|
|
10
28
|
atom.reportObserved();
|
|
11
29
|
}
|
|
12
|
-
if (prop === 'onValuesChange') {
|
|
13
|
-
atom.reportChanged();
|
|
14
|
-
}
|
|
15
30
|
return Reflect.get(target, prop, receiver);
|
|
16
31
|
},
|
|
17
32
|
});
|
|
@@ -1,4 +1,16 @@
|
|
|
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
|
+
*/
|
|
2
14
|
export type ObservableReference<T> = LiveReference<T>;
|
|
3
15
|
export declare const ObservableReference: <T>(sourceReference: LiveReference<T>) => LiveReference<T>;
|
|
4
16
|
//# sourceMappingURL=ObservableReference.d.ts.map
|
|
@@ -2,23 +2,27 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ObservableReference = void 0;
|
|
4
4
|
const mobx_1 = require("mobx");
|
|
5
|
-
const
|
|
5
|
+
const observingAtoms = Symbol('@data-weave/observableReference.observingAtoms');
|
|
6
6
|
const ObservableReference = (sourceReference) => {
|
|
7
7
|
const atom = (0, mobx_1.createAtom)('ObservableReference', () => sourceReference.resolve(), () => sourceReference.unsubscribe());
|
|
8
|
-
// FirestoreReference (and any LiveReference) calls `this.onUpdate(...)`
|
|
9
|
-
// the bare instance from inside its snapshot callback, which then
|
|
10
|
-
// `this.onValueChange()` on the bare instance too. The Proxy's
|
|
11
|
-
// never sees that call, so we
|
|
12
|
-
//
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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;
|
|
16
18
|
const original = sourceReference.onValueChange.bind(sourceReference);
|
|
17
19
|
sourceReference.onValueChange = () => {
|
|
18
20
|
original();
|
|
19
|
-
|
|
21
|
+
for (const a of atoms)
|
|
22
|
+
a.reportChanged();
|
|
20
23
|
};
|
|
21
24
|
}
|
|
25
|
+
bridged[observingAtoms].push(atom);
|
|
22
26
|
return new Proxy(sourceReference, {
|
|
23
27
|
get(target, prop, receiver) {
|
|
24
28
|
if (prop === 'value' || prop === 'resolved' || prop === 'hasError' || prop === 'error') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@data-weave/datamanager-mobx",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.4",
|
|
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.
|
|
27
|
-
"@data-weave/datamanager": "~0.6.
|
|
26
|
+
"@data-weave/backend-firestore": "~0.6.4",
|
|
27
|
+
"@data-weave/datamanager": "~0.6.4"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"mobx": ">=6.0.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@data-weave/backend-firestore": "~0.6.
|
|
34
|
-
"@data-weave/datamanager": "~0.6.
|
|
33
|
+
"@data-weave/backend-firestore": "~0.6.4",
|
|
34
|
+
"@data-weave/datamanager": "~0.6.4",
|
|
35
35
|
"mobx": "6.15.0",
|
|
36
36
|
"typescript": "5.9.3"
|
|
37
37
|
},
|