@livequery/client 2.0.2 → 2.0.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/build/Collection.js +45 -33
- package/package.json +1 -1
package/build/Collection.js
CHANGED
|
@@ -9,14 +9,15 @@ export class CollectionObservable extends Observable {
|
|
|
9
9
|
#sorters = new Array;
|
|
10
10
|
#IdMap = new Map();
|
|
11
11
|
#refs = [];
|
|
12
|
-
|
|
13
|
-
items: [],
|
|
14
|
-
loading: false,
|
|
15
|
-
options: {},
|
|
16
|
-
paging: {}
|
|
17
|
-
});
|
|
12
|
+
$;
|
|
18
13
|
constructor(ref, collection_options) {
|
|
19
14
|
super(o => {
|
|
15
|
+
this.$ = new BehaviorSubject({
|
|
16
|
+
items: [],
|
|
17
|
+
loading: false,
|
|
18
|
+
options: collection_options.options || {},
|
|
19
|
+
paging: {}
|
|
20
|
+
});
|
|
20
21
|
const linker = this.$.subscribe(o);
|
|
21
22
|
return () => {
|
|
22
23
|
linker.unsubscribe();
|
|
@@ -72,32 +73,38 @@ export class CollectionObservable extends Observable {
|
|
|
72
73
|
if (
|
|
73
74
|
// Is first value from HTTP query
|
|
74
75
|
true
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
76
|
+
|| (
|
|
77
|
+
// Is realtime update that match filters
|
|
78
|
+
(realtime || from_local) && Object
|
|
79
|
+
.keys(state.options || {})
|
|
80
|
+
.filter(key => !key.includes('_'))
|
|
81
|
+
.every(key => {
|
|
82
|
+
try {
|
|
83
|
+
const [field, expression] = key.split(':');
|
|
84
|
+
const a = payload[field];
|
|
85
|
+
const b = state.options?.[field];
|
|
86
|
+
if (!expression)
|
|
87
|
+
return a == b;
|
|
88
|
+
if (expression == 'ne')
|
|
89
|
+
return a != b;
|
|
90
|
+
if (expression == 'lt')
|
|
91
|
+
return typeof a == 'number' && typeof b == 'number' && a < b;
|
|
92
|
+
if (expression == 'lte')
|
|
93
|
+
return typeof a == 'number' && typeof b == 'number' && a <= b;
|
|
94
|
+
if (expression == 'gt')
|
|
95
|
+
return typeof a == 'number' && typeof b == 'number' && a > b;
|
|
96
|
+
if (expression == 'gte')
|
|
97
|
+
return typeof a == 'number' && typeof b == 'number' && a >= b;
|
|
98
|
+
if (expression == 'in' || expression == 'like')
|
|
99
|
+
return Array.isArray(a) && a?.includes(b);
|
|
100
|
+
if (expression == 'between') {
|
|
101
|
+
const [x, y] = b;
|
|
102
|
+
return x <= a && a <= y;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch (e) { }
|
|
106
|
+
return false;
|
|
107
|
+
}))) {
|
|
101
108
|
const item = {
|
|
102
109
|
...payload,
|
|
103
110
|
__adding: false,
|
|
@@ -166,7 +173,12 @@ export class CollectionObservable extends Observable {
|
|
|
166
173
|
this.#IdMap.clear();
|
|
167
174
|
state.items.map((item, index) => this.#IdMap.set(item.id, index));
|
|
168
175
|
}
|
|
169
|
-
if (
|
|
176
|
+
if (state.paging.count) {
|
|
177
|
+
const d = state.items.length - state.paging.count.current;
|
|
178
|
+
state.paging.count.current = state.items.length;
|
|
179
|
+
state.paging.count.total += d;
|
|
180
|
+
}
|
|
181
|
+
if (direction && stream.some(d => d.data?.paging)) {
|
|
170
182
|
// Cache paging
|
|
171
183
|
this.#pages.clear();
|
|
172
184
|
stream.forEach(s => s.data?.paging && this.#pages.set(s.ref, s.data?.paging));
|