@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.
Files changed (2) hide show
  1. package/build/Collection.js +42 -27
  2. package/package.json +1 -1
@@ -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
- // // 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
- ) {
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 (direction && stream.some(s => !!s.data?.paging)) {
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));
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.3",
7
+ "version": "2.0.5",
8
8
  "description": "",
9
9
  "main": "build/index.js",
10
10
  "types": "build/index.d.ts",