@livequery/client 1.0.31 → 1.0.32

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.
@@ -34,6 +34,7 @@ var _CollectionObservable_$state, _CollectionObservable_subscriptions, _Collecti
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
35
  exports.CollectionObservable = void 0;
36
36
  const rxjs_1 = require("rxjs");
37
+ const get_sort_function_1 = require("./helpers/get_sort_function");
37
38
  const operators_1 = require("rxjs/operators");
38
39
  class CollectionObservable extends rxjs_1.Observable {
39
40
  set_realtime(realtime) {
@@ -148,6 +149,7 @@ class CollectionObservable extends rxjs_1.Observable {
148
149
  }
149
150
  }
150
151
  }
152
+ actions.reindex && __classPrivateFieldGet(this, _CollectionObservable_state, "f").items.sort((0, get_sort_function_1.get_sort_function)(__classPrivateFieldGet(this, _CollectionObservable_state, "f").items[0], this.collection_options.filters._order_by || 'created_at', this.collection_options.filters._sort));
151
153
  actions.reindex && (__classPrivateFieldGet(this, _CollectionObservable_IdMap, "f").clear(), __classPrivateFieldGet(this, _CollectionObservable_state, "f").items.map((item, index) => __classPrivateFieldGet(this, _CollectionObservable_IdMap, "f").set(item.id, index)));
152
154
  actions.update && __classPrivateFieldGet(this, _CollectionObservable_$state, "f").next(__classPrivateFieldGet(this, _CollectionObservable_state, "f"));
153
155
  }
@@ -5,15 +5,16 @@ function get_sort_function(data, key, order = 'desc') {
5
5
  const type = typeof (data === null || data === void 0 ? void 0 : data[key]);
6
6
  if (type == 'bigint' || type == 'number') {
7
7
  if (order == 'asc')
8
- return (a, b) => a[key] - b[key];
8
+ return (a, b) => a[key] - b[key] || ((a.created_at || 1) - (b.created_at || 0));
9
9
  if (order == 'desc')
10
- return (a, b) => b[key] - a[key];
10
+ return (a, b) => b[key] - a[key] || ((a.created_at || 1) - (b.created_at || 0));
11
11
  }
12
12
  if (type == 'string') {
13
13
  if (order == 'asc')
14
- return (a, b) => a[key].localeCompare(b[key]);
14
+ return (a, b) => a[key].localeCompare(b[key]) || ((a.created_at || 1) - (b.created_at || 0));
15
15
  if (order == 'desc')
16
- return (a, b) => b[key].localeCompare(a[key]);
16
+ return (a, b) => b[key].localeCompare(a[key]) || ((a.created_at || 1) - (b.created_at || 0));
17
17
  }
18
+ return () => 1;
18
19
  }
19
20
  exports.get_sort_function = get_sort_function;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "repository": {
4
4
  "url": "https://github.com/livequery/client"
5
5
  },
6
- "version": "1.0.31",
6
+ "version": "1.0.32",
7
7
  "description": "",
8
8
  "main": "build/index.js",
9
9
  "types": "build/index.d.ts",