@lavalogic/scoria 0.11.13 → 0.11.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.
@@ -82,11 +82,8 @@ export class TableContext {
82
82
  const sd = (() => {
83
83
  if (this.paginationRepo?.paginationType == PaginationType.Local) {
84
84
  const state = dataRepo.sorting ?? [];
85
- const sortedData = this.showSelectedOnly
86
- ? // FIXME this will show the selected items by order of insertion to the selectedItems map.
87
- [...this.selectedItems.values()]
88
- : fd.concat();
89
- sortedData.sort((a, b) => {
85
+ const dataToSort = fd.concat();
86
+ dataToSort.sort((a, b) => {
90
87
  const end = state.length;
91
88
  for (let i = 0; i < end; i++) {
92
89
  const { id, desc } = state[i];
@@ -97,13 +94,13 @@ export class TableContext {
97
94
  return result;
98
95
  }
99
96
  }
100
- else {
97
+ else if (dev) {
101
98
  console.warn('no sorting fn found for ' + id);
102
99
  }
103
100
  }
104
101
  return 0;
105
102
  });
106
- return sortedData;
103
+ return dataToSort;
107
104
  }
108
105
  return fd ?? [];
109
106
  })();
@@ -111,7 +108,11 @@ export class TableContext {
111
108
  if (dataRepo.paginationType != PaginationType.Local) {
112
109
  return sd ?? [];
113
110
  }
114
- return sd.slice(dataRepo.pageStartIndex, dataRepo.pageEndIndexExclusive);
111
+ const x = sd.slice(dataRepo.pageStartIndex, dataRepo.pageEndIndexExclusive);
112
+ if (dev) {
113
+ console.log(x);
114
+ }
115
+ return x;
115
116
  })();
116
117
  const ori = new Map((dataRepo.data ?? []).map((item, index) => [item, index]));
117
118
  this._filteredData = fd;
@@ -218,7 +219,7 @@ export class TableContext {
218
219
  void this.dataRepo?.data;
219
220
  (async () => {
220
221
  const startTime = Date.now();
221
- let currentTimerPromise;
222
+ let currentTimer;
222
223
  const abortController = new AbortController();
223
224
  try {
224
225
  if (this.paginationRepo?.paginationType == PaginationType.Local) {
@@ -245,56 +246,66 @@ export class TableContext {
245
246
  // console.warn(`key ${key} was already checked, new value:`, value);
246
247
  // }
247
248
  // });
248
- if (!filterState.length) {
249
- this.filteredIndices = data.map((_, index) => index) ?? [];
250
- }
251
- currentTimerPromise = this.filterTimer = this.filterTimer + 1;
249
+ currentTimer = ++this.filterTimer;
252
250
  await asyncSleep(150);
253
- const currentTimer = await currentTimerPromise;
254
- if (currentTimerPromise != this.filterTimer) {
251
+ if (currentTimer != this.filterTimer) {
255
252
  throw new Error('stale filter');
256
253
  }
257
- let settled = false;
258
- const filterPromise = asyncFilterIndices(data, async (item, index) => {
259
- const row = this.createRow(item, index, index);
260
- return asyncAll(filterState, async (filter) => {
261
- abortController.signal.throwIfAborted();
262
- const def = this.columnDefsById.get(filter.id);
263
- if (!def) {
264
- console.warn(`Could not find column def for filter with id ${filter.id}`);
265
- return false;
266
- }
267
- if (def.filterFn) {
268
- return def.filterFn(row, filter.id, filter.value);
254
+ if (!filterState.length) {
255
+ this.filteredIndices =
256
+ data.map((item, index) => {
257
+ if (item == null) {
258
+ throw new Error(`found a nullish data item at index ${index}`);
259
+ }
260
+ return index;
261
+ }) ?? [];
262
+ }
263
+ else {
264
+ let settled = false;
265
+ const filterPromise = asyncFilterIndices(data, async (item, index) => {
266
+ if (item == null) {
267
+ throw new Error(`Found a nullish data item at async filter at index ${index}`);
269
268
  }
269
+ const row = this.createRow(item, index, index);
270
+ return asyncAll(filterState, async (filter) => {
271
+ abortController.signal.throwIfAborted();
272
+ const def = this.columnDefsById.get(filter.id);
273
+ if (!def) {
274
+ console.warn(`Could not find column def for filter with id ${filter.id}`);
275
+ return false;
276
+ }
277
+ if (def.filterFn) {
278
+ return def.filterFn(row, filter.id, filter.value);
279
+ }
280
+ if (dev) {
281
+ console.warn(`column ${def.id} did not have a filter function`);
282
+ }
283
+ return false;
284
+ });
285
+ });
286
+ filterPromise
287
+ .then((indices) => {
288
+ this.filteredIndices = indices;
289
+ })
290
+ .catch((e) => {
270
291
  if (dev) {
271
- console.warn(`column ${def.id} did not have a filter function`);
292
+ console.log(`caught filter rejection:`, e);
293
+ console.log(`iteration ${currentTimer} cancelled after ${Date.now() - startTime}ms`);
272
294
  }
273
- return false;
295
+ })
296
+ .finally(() => {
297
+ settled = true;
274
298
  });
275
- });
276
- filterPromise
277
- .then((indices) => {
278
- this.filteredIndices = indices;
279
- })
280
- .catch((e) => {
281
- if (dev) {
282
- console.log(`caught filter rejection:`, e);
283
- console.log(`iteration ${currentTimer} cancelled after ${Date.now() - startTime}ms`);
284
- }
285
- })
286
- .finally(() => {
287
- settled = true;
288
- });
289
- for (;;) {
290
- if (currentTimerPromise !== this.filterTimer) {
291
- abortController.abort('stale data');
292
- }
293
- if (settled) {
294
- console.log(`iteration ${await currentTimerPromise} finished ${Date.now() - startTime}ms`);
295
- return;
299
+ for (;;) {
300
+ if (currentTimer !== this.filterTimer) {
301
+ abortController.abort('stale data');
302
+ }
303
+ if (settled) {
304
+ console.log(`iteration ${currentTimer} finished ${Date.now() - startTime}ms`);
305
+ return;
306
+ }
307
+ await tick();
296
308
  }
297
- await tick();
298
309
  }
299
310
  }
300
311
  }
@@ -304,7 +315,7 @@ export class TableContext {
304
315
  if (!message.toLocaleLowerCase().startsWith('stale')) {
305
316
  console.error(e);
306
317
  }
307
- console.log(`iteration ${await currentTimerPromise} cancelled after ${Date.now() - startTime}ms`);
318
+ console.log(`iteration ${await currentTimer} cancelled after ${Date.now() - startTime}ms`);
308
319
  }
309
320
  }
310
321
  })();
@@ -713,8 +724,8 @@ export class TableContext {
713
724
  return this._originalRowIndices;
714
725
  }
715
726
  paginationRowModel = $derived.by(() => {
716
- const sortedData = this._currentPageData;
717
- const rows = sortedData.map((item, index) => {
727
+ const currentPageData = this._currentPageData;
728
+ const rows = currentPageData.map((item, index) => {
718
729
  const unsortedIndex = this._originalRowIndices.get(item) ?? index;
719
730
  if (!item) {
720
731
  throw new Error(`No Item was found at index ${index}`);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lavalogic/scoria",
3
3
  "description": "Svelte components used for the FloWMS Web Frontend",
4
- "version": "0.11.13",
4
+ "version": "0.11.15",
5
5
  "publishConfig": {
6
6
  "access": "restricted"
7
7
  },