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