@data-weave/datamanager 0.6.2 → 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/LiveList.js +3 -0
- package/dist/OptimisticReference.d.ts +1 -11
- package/dist/OptimisticReference.js +9 -15
- package/package.json +1 -1
package/dist/LiveList.js
CHANGED
|
@@ -41,12 +41,15 @@ class LiveList {
|
|
|
41
41
|
}
|
|
42
42
|
onUpdateAtIndex(index, value) {
|
|
43
43
|
this._values[index] = value;
|
|
44
|
+
this.onUpdate();
|
|
44
45
|
}
|
|
45
46
|
onAddAtIndex(index, value) {
|
|
46
47
|
this._values.splice(index, 0, value);
|
|
48
|
+
this.onUpdate();
|
|
47
49
|
}
|
|
48
50
|
onRemoveAtIndex(index) {
|
|
49
51
|
this._values.splice(index, 1);
|
|
52
|
+
this.onUpdate();
|
|
50
53
|
}
|
|
51
54
|
onError(error) {
|
|
52
55
|
this._hasError = true;
|
|
@@ -1,19 +1,8 @@
|
|
|
1
1
|
import type { Reference } from './Reference';
|
|
2
2
|
export type Patch<T> = Partial<T> | ((current: T) => Partial<T>);
|
|
3
|
-
/**
|
|
4
|
-
* Wraps a `Reference<T>` and overlays an optimistic `_patch` on top of the
|
|
5
|
-
* source value. The patch is automatically discarded the next time the source
|
|
6
|
-
* publishes a new value (detected lazily by comparing the source value against
|
|
7
|
-
* the snapshot the patch was applied against).
|
|
8
|
-
*
|
|
9
|
-
* This class is intentionally mobx-free. For reactive consumers, wrap the
|
|
10
|
-
* instance with `ObservableOptimisticReference` from
|
|
11
|
-
* `@data-weave/datamanager-mobx`.
|
|
12
|
-
*/
|
|
13
3
|
export declare class OptimisticReference<T extends object> implements Reference<T> {
|
|
14
4
|
private readonly source;
|
|
15
5
|
private _patch;
|
|
16
|
-
private _patchedAgainstSnapshot;
|
|
17
6
|
constructor(source: Reference<T>);
|
|
18
7
|
get value(): T | undefined;
|
|
19
8
|
get resolved(): boolean;
|
|
@@ -24,5 +13,6 @@ export declare class OptimisticReference<T extends object> implements Reference<
|
|
|
24
13
|
clearOptimistic(): void;
|
|
25
14
|
get hasPendingOptimistic(): boolean;
|
|
26
15
|
dispose(): void;
|
|
16
|
+
private patchMatches;
|
|
27
17
|
}
|
|
28
18
|
//# sourceMappingURL=OptimisticReference.d.ts.map
|
|
@@ -1,28 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OptimisticReference = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Wraps a `Reference<T>` and overlays an optimistic `_patch` on top of the
|
|
6
|
-
* source value. The patch is automatically discarded the next time the source
|
|
7
|
-
* publishes a new value (detected lazily by comparing the source value against
|
|
8
|
-
* the snapshot the patch was applied against).
|
|
9
|
-
*
|
|
10
|
-
* This class is intentionally mobx-free. For reactive consumers, wrap the
|
|
11
|
-
* instance with `ObservableOptimisticReference` from
|
|
12
|
-
* `@data-weave/datamanager-mobx`.
|
|
13
|
-
*/
|
|
14
4
|
class OptimisticReference {
|
|
15
5
|
source;
|
|
16
6
|
_patch;
|
|
17
|
-
_patchedAgainstSnapshot;
|
|
18
7
|
constructor(source) {
|
|
19
8
|
this.source = source;
|
|
20
9
|
}
|
|
21
10
|
get value() {
|
|
22
11
|
const base = this.source.value;
|
|
23
|
-
if (this._patch !== undefined && base !== this.
|
|
12
|
+
if (this._patch !== undefined && base !== undefined && this.patchMatches(base, this._patch)) {
|
|
13
|
+
// Source has caught up to the optimistic write; safe to discard.
|
|
24
14
|
this._patch = undefined;
|
|
25
|
-
this._patchedAgainstSnapshot = undefined;
|
|
26
15
|
}
|
|
27
16
|
if (!this._patch)
|
|
28
17
|
return base;
|
|
@@ -46,16 +35,21 @@ class OptimisticReference {
|
|
|
46
35
|
const current = this.value ?? {};
|
|
47
36
|
const resolved = typeof patch === 'function' ? patch(current) : patch;
|
|
48
37
|
this._patch = { ...this._patch, ...resolved };
|
|
49
|
-
this._patchedAgainstSnapshot = this.source.value;
|
|
50
38
|
}
|
|
51
39
|
clearOptimistic() {
|
|
52
40
|
this._patch = undefined;
|
|
53
|
-
this._patchedAgainstSnapshot = undefined;
|
|
54
41
|
}
|
|
55
42
|
get hasPendingOptimistic() {
|
|
56
43
|
return this._patch !== undefined;
|
|
57
44
|
}
|
|
58
45
|
dispose() { }
|
|
46
|
+
patchMatches(base, patch) {
|
|
47
|
+
for (const key of Object.keys(patch)) {
|
|
48
|
+
if (!Object.is(base[key], patch[key]))
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
59
53
|
}
|
|
60
54
|
exports.OptimisticReference = OptimisticReference;
|
|
61
55
|
//# sourceMappingURL=OptimisticReference.js.map
|