@livequery/client 2.0.7 → 2.0.15
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 +10 -5
- package/package.json +1 -1
package/build/Collection.js
CHANGED
|
@@ -109,6 +109,7 @@ export class CollectionObservable extends BehaviorSubject {
|
|
|
109
109
|
}))) {
|
|
110
110
|
const item = {
|
|
111
111
|
...payload,
|
|
112
|
+
id: payload.id || payload._id,
|
|
112
113
|
__adding: false,
|
|
113
114
|
__updating: false,
|
|
114
115
|
__removing: false,
|
|
@@ -175,7 +176,7 @@ export class CollectionObservable extends BehaviorSubject {
|
|
|
175
176
|
this.#IdMap.clear();
|
|
176
177
|
state.items.map((item, index) => this.#IdMap.set(item.id, index));
|
|
177
178
|
}
|
|
178
|
-
if (state.paging
|
|
179
|
+
if (state.paging?.count) {
|
|
179
180
|
const d = state.items.length - state.paging.count.current;
|
|
180
181
|
state.paging.count.current = state.items.length;
|
|
181
182
|
state.paging.count.total += d;
|
|
@@ -201,8 +202,8 @@ export class CollectionObservable extends BehaviorSubject {
|
|
|
201
202
|
prev: stream.some(s => s.data?.paging?.has?.prev)
|
|
202
203
|
},
|
|
203
204
|
page: {
|
|
204
|
-
current: Math.min(...stream.map(s => s.data?.paging?.page
|
|
205
|
-
total: Math.max(...stream.map(s => s.data?.paging?.page
|
|
205
|
+
current: Math.min(...stream.map(s => s.data?.paging?.page?.current || 0)),
|
|
206
|
+
total: Math.max(...stream.map(s => s.data?.paging?.page?.total || 0))
|
|
206
207
|
}
|
|
207
208
|
};
|
|
208
209
|
}
|
|
@@ -241,7 +242,7 @@ export class CollectionObservable extends BehaviorSubject {
|
|
|
241
242
|
const paging = this.#pages.get(ref);
|
|
242
243
|
if (!paging)
|
|
243
244
|
return true;
|
|
244
|
-
return loading == 'forward' ? paging.has
|
|
245
|
+
return loading == 'forward' ? paging.has?.next : paging.has?.prev;
|
|
245
246
|
});
|
|
246
247
|
const no_more_data = !flush && (remain_data_refs.length == 0 || this.getValue().loading);
|
|
247
248
|
if (no_more_data)
|
|
@@ -299,7 +300,11 @@ export class CollectionObservable extends BehaviorSubject {
|
|
|
299
300
|
return { ref, id, collection_ref, index };
|
|
300
301
|
}
|
|
301
302
|
async add(payload) {
|
|
302
|
-
|
|
303
|
+
const r = await this.collection_options.transporter.add(`${this.ref}`, payload);
|
|
304
|
+
if (r.data && r.data.item && !r.data.item.id) {
|
|
305
|
+
r.data.item.id = r.data.item._id;
|
|
306
|
+
}
|
|
307
|
+
return r;
|
|
303
308
|
}
|
|
304
309
|
async update({ id: update_payload_id, ...payload }) {
|
|
305
310
|
const { id, ref } = this.#find_ref_by_id(update_payload_id);
|