@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.
Files changed (2) hide show
  1. package/build/Collection.js +45 -33
  2. package/package.json +1 -1
@@ -9,14 +9,15 @@ export class CollectionObservable extends Observable {
9
9
  #sorters = new Array;
10
10
  #IdMap = new Map();
11
11
  #refs = [];
12
- $ = new BehaviorSubject({
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
- // // Is realtime update that match filters
77
- // (realtime || from_local) && Object
78
- // .keys(state.options || {})
79
- // .filter(key => !key.includes('_'))
80
- // .every(key => {
81
- // try {
82
- // const [field, expression] = key.split(':')
83
- // const a = payload[field as keyof typeof payload] as number
84
- // const b = state.options?.[field as keyof QueryOption<T>] as any as number
85
- // if (!expression) return a == b
86
- // if (expression == 'ne') return a != b
87
- // if (expression == 'lt') return typeof a == 'number' && typeof b == 'number' && a < b
88
- // if (expression == 'lte') return typeof a == 'number' && typeof b == 'number' && a <= b
89
- // if (expression == 'gt') return typeof a == 'number' && typeof b == 'number' && a > b
90
- // if (expression == 'gte') return typeof a == 'number' && typeof b == 'number' && a >= b
91
- // if (expression == 'in' || expression == 'like') return Array.isArray(a) && a?.includes(b)
92
- // if (expression == 'between') {
93
- // const [x, y] = b as any as number[]
94
- // return x <= a && a <= y
95
- // }
96
- // } catch (e) { }
97
- // return false
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 (direction) {
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));
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "repository": {
5
5
  "url": "https://github.com/livequery/client"
6
6
  },
7
- "version": "2.0.2",
7
+ "version": "2.0.4",
8
8
  "description": "",
9
9
  "main": "build/index.js",
10
10
  "types": "build/index.d.ts",