@data-weave/datamanager 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/LiveList.d.ts +3 -1
- package/dist/LiveList.js +10 -3
- package/dist/LiveReference.d.ts +4 -2
- package/dist/LiveReference.js +11 -4
- package/dist/OptimisticReference.d.ts +6 -5
- package/dist/OptimisticReference.js +20 -15
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/package.json +1 -1
package/dist/LiveList.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare class LiveList<T> implements List<T> {
|
|
|
14
14
|
private _hasError;
|
|
15
15
|
private _error;
|
|
16
16
|
private _options;
|
|
17
|
+
private _listeners;
|
|
17
18
|
constructor(options: LiveListOptions<T>);
|
|
18
19
|
resolve(): Promise<readonly T[]>;
|
|
19
20
|
get values(): T[];
|
|
@@ -21,7 +22,6 @@ export declare class LiveList<T> implements List<T> {
|
|
|
21
22
|
get resolved(): boolean;
|
|
22
23
|
protected setStale(): void;
|
|
23
24
|
get error(): unknown;
|
|
24
|
-
onValuesChange(): void;
|
|
25
25
|
unsubscribe(): void;
|
|
26
26
|
protected onUpdate(): void;
|
|
27
27
|
protected onUpdateAll(values: T[]): void;
|
|
@@ -29,5 +29,7 @@ export declare class LiveList<T> implements List<T> {
|
|
|
29
29
|
protected onAddAtIndex(index: number, value: T): void;
|
|
30
30
|
protected onRemoveAtIndex(index: number): void;
|
|
31
31
|
protected onError(error: unknown): void;
|
|
32
|
+
protected notifyChange(): void;
|
|
33
|
+
registerOnChangeListener(onChange: () => void): void;
|
|
32
34
|
}
|
|
33
35
|
//# sourceMappingURL=LiveList.d.ts.map
|
package/dist/LiveList.js
CHANGED
|
@@ -7,6 +7,7 @@ class LiveList {
|
|
|
7
7
|
_hasError = false;
|
|
8
8
|
_error;
|
|
9
9
|
_options;
|
|
10
|
+
_listeners = [];
|
|
10
11
|
constructor(options) {
|
|
11
12
|
this._options = options;
|
|
12
13
|
}
|
|
@@ -24,16 +25,16 @@ class LiveList {
|
|
|
24
25
|
}
|
|
25
26
|
setStale() {
|
|
26
27
|
this._resolved = false;
|
|
28
|
+
this.notifyChange();
|
|
27
29
|
}
|
|
28
30
|
get error() {
|
|
29
31
|
return this._error;
|
|
30
32
|
}
|
|
31
|
-
onValuesChange() { }
|
|
32
33
|
unsubscribe() { }
|
|
33
34
|
onUpdate() {
|
|
34
35
|
this._resolved = true;
|
|
35
|
-
this.onValuesChange();
|
|
36
36
|
this._options.onUpdate?.(this._values);
|
|
37
|
+
this.notifyChange();
|
|
37
38
|
}
|
|
38
39
|
onUpdateAll(values) {
|
|
39
40
|
this._values = values;
|
|
@@ -59,7 +60,13 @@ class LiveList {
|
|
|
59
60
|
this._values = [];
|
|
60
61
|
}
|
|
61
62
|
this._options.onError?.(error);
|
|
62
|
-
this.
|
|
63
|
+
this.notifyChange();
|
|
64
|
+
}
|
|
65
|
+
notifyChange() {
|
|
66
|
+
this._listeners.forEach(listener => listener());
|
|
67
|
+
}
|
|
68
|
+
registerOnChangeListener(onChange) {
|
|
69
|
+
this._listeners.push(onChange);
|
|
63
70
|
}
|
|
64
71
|
}
|
|
65
72
|
exports.LiveList = LiveList;
|
package/dist/LiveReference.d.ts
CHANGED
|
@@ -15,16 +15,18 @@ export declare class LiveReference<T> implements IdentifiableReference<T> {
|
|
|
15
15
|
private _hasError;
|
|
16
16
|
private _error;
|
|
17
17
|
private _options;
|
|
18
|
+
private _listeners;
|
|
18
19
|
resolve(): Promise<T | undefined>;
|
|
19
20
|
constructor(id: string, options: LiveReferenceOptions<T>);
|
|
20
21
|
get value(): T | undefined;
|
|
21
22
|
get resolved(): boolean;
|
|
22
23
|
get hasError(): boolean;
|
|
23
24
|
get error(): unknown;
|
|
24
|
-
protected
|
|
25
|
+
protected onStale(): void;
|
|
25
26
|
protected onUpdate(data: T | undefined): void;
|
|
26
27
|
protected onError(error: unknown): void;
|
|
27
|
-
onValueChange(): void;
|
|
28
28
|
unsubscribe(): void;
|
|
29
|
+
protected notifyChange(): void;
|
|
30
|
+
registerOnChangeListener(onChange: () => void): void;
|
|
29
31
|
}
|
|
30
32
|
//# sourceMappingURL=LiveReference.d.ts.map
|
package/dist/LiveReference.js
CHANGED
|
@@ -8,6 +8,7 @@ class LiveReference {
|
|
|
8
8
|
_hasError = false;
|
|
9
9
|
_error;
|
|
10
10
|
_options;
|
|
11
|
+
_listeners = [];
|
|
11
12
|
resolve() {
|
|
12
13
|
throw new Error('Method not implemented.');
|
|
13
14
|
}
|
|
@@ -30,15 +31,16 @@ class LiveReference {
|
|
|
30
31
|
get error() {
|
|
31
32
|
return this._error;
|
|
32
33
|
}
|
|
33
|
-
|
|
34
|
+
onStale() {
|
|
34
35
|
this._resolved = false;
|
|
36
|
+
this.notifyChange();
|
|
35
37
|
}
|
|
36
38
|
onUpdate(data) {
|
|
37
39
|
this._value = data;
|
|
38
40
|
this._resolved = true;
|
|
39
41
|
this._hasError = false;
|
|
40
|
-
this.onValueChange();
|
|
41
42
|
this._options.onUpdate?.(this._value);
|
|
43
|
+
this.notifyChange();
|
|
42
44
|
}
|
|
43
45
|
onError(error) {
|
|
44
46
|
this._hasError = true;
|
|
@@ -47,11 +49,16 @@ class LiveReference {
|
|
|
47
49
|
}
|
|
48
50
|
this._resolved = true;
|
|
49
51
|
this._error = error;
|
|
50
|
-
this.onValueChange();
|
|
51
52
|
this._options.onError?.(error);
|
|
53
|
+
this.notifyChange();
|
|
52
54
|
}
|
|
53
|
-
onValueChange() { }
|
|
54
55
|
unsubscribe() { }
|
|
56
|
+
notifyChange() {
|
|
57
|
+
this._listeners.forEach(listener => listener());
|
|
58
|
+
}
|
|
59
|
+
registerOnChangeListener(onChange) {
|
|
60
|
+
this._listeners.push(onChange);
|
|
61
|
+
}
|
|
55
62
|
}
|
|
56
63
|
exports.LiveReference = LiveReference;
|
|
57
64
|
//# sourceMappingURL=LiveReference.js.map
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { LiveReference, LiveReferenceOptions } from './LiveReference';
|
|
2
2
|
export type Patch<T> = Partial<T> | ((current: T) => Partial<T>);
|
|
3
|
-
export declare class OptimisticReference<T extends
|
|
3
|
+
export declare class OptimisticReference<T> extends LiveReference<T> {
|
|
4
4
|
private readonly source;
|
|
5
5
|
private _patch;
|
|
6
|
-
|
|
6
|
+
private _opts;
|
|
7
|
+
constructor(source: LiveReference<T>, options?: LiveReferenceOptions<T>);
|
|
7
8
|
get value(): T | undefined;
|
|
8
9
|
get resolved(): boolean;
|
|
9
10
|
get hasError(): boolean;
|
|
10
11
|
get error(): unknown | undefined;
|
|
11
12
|
resolve(): Promise<T | undefined>;
|
|
13
|
+
protected onUpdate(data: T | undefined): void;
|
|
12
14
|
applyOptimistic(patch: Patch<T>): void;
|
|
13
15
|
clearOptimistic(): void;
|
|
14
16
|
get hasPendingOptimistic(): boolean;
|
|
15
|
-
|
|
16
|
-
private patchMatches;
|
|
17
|
+
unsubscribe(): void;
|
|
17
18
|
}
|
|
18
19
|
//# sourceMappingURL=OptimisticReference.d.ts.map
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OptimisticReference = void 0;
|
|
4
|
-
|
|
4
|
+
const LiveReference_1 = require("./LiveReference");
|
|
5
|
+
class OptimisticReference extends LiveReference_1.LiveReference {
|
|
5
6
|
source;
|
|
6
7
|
_patch;
|
|
7
|
-
|
|
8
|
+
_opts;
|
|
9
|
+
constructor(source, options = {}) {
|
|
10
|
+
super(source.id, options);
|
|
8
11
|
this.source = source;
|
|
12
|
+
this.source.registerOnChangeListener(() => this.notifyChange());
|
|
13
|
+
this._opts = options;
|
|
9
14
|
}
|
|
10
15
|
get value() {
|
|
11
16
|
const base = this.source.value;
|
|
12
|
-
if (this._patch !== undefined && base !== undefined && this.patchMatches(base, this._patch)) {
|
|
13
|
-
// Source has caught up to the optimistic write; safe to discard.
|
|
14
|
-
this._patch = undefined;
|
|
15
|
-
}
|
|
16
17
|
if (!this._patch)
|
|
17
18
|
return base;
|
|
18
19
|
if (!base)
|
|
@@ -28,27 +29,31 @@ class OptimisticReference {
|
|
|
28
29
|
get error() {
|
|
29
30
|
return this.source.error;
|
|
30
31
|
}
|
|
31
|
-
resolve() {
|
|
32
|
-
|
|
32
|
+
async resolve() {
|
|
33
|
+
await this.source.resolve();
|
|
34
|
+
return this.value;
|
|
35
|
+
}
|
|
36
|
+
onUpdate(data) {
|
|
37
|
+
if (this._opts.clearOptimisticOnSourceUpdate) {
|
|
38
|
+
this.clearOptimistic();
|
|
39
|
+
}
|
|
40
|
+
super.onUpdate(data);
|
|
33
41
|
}
|
|
34
42
|
applyOptimistic(patch) {
|
|
35
43
|
const current = this.value ?? {};
|
|
36
44
|
const resolved = typeof patch === 'function' ? patch(current) : patch;
|
|
37
45
|
this._patch = { ...this._patch, ...resolved };
|
|
46
|
+
this.notifyChange();
|
|
38
47
|
}
|
|
39
48
|
clearOptimistic() {
|
|
40
49
|
this._patch = undefined;
|
|
50
|
+
this.notifyChange();
|
|
41
51
|
}
|
|
42
52
|
get hasPendingOptimistic() {
|
|
43
53
|
return this._patch !== undefined;
|
|
44
54
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
for (const key of Object.keys(patch)) {
|
|
48
|
-
if (!Object.is(base[key], patch[key]))
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
return true;
|
|
55
|
+
unsubscribe() {
|
|
56
|
+
this.source.unsubscribe();
|
|
52
57
|
}
|
|
53
58
|
}
|
|
54
59
|
exports.OptimisticReference = OptimisticReference;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -19,6 +19,5 @@ __exportStar(require("./DataManager"), exports);
|
|
|
19
19
|
__exportStar(require("./List"), exports);
|
|
20
20
|
__exportStar(require("./LiveList"), exports);
|
|
21
21
|
__exportStar(require("./LiveReference"), exports);
|
|
22
|
-
__exportStar(require("./OptimisticReference"), exports);
|
|
23
22
|
__exportStar(require("./Reference"), exports);
|
|
24
23
|
//# sourceMappingURL=index.js.map
|