neo.mjs 6.15.7 → 6.15.8
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/apps/ServiceWorker.mjs +2 -2
- package/examples/ServiceWorker.mjs +2 -2
- package/package.json +1 -1
- package/src/DefaultConfig.mjs +2 -2
- package/src/collection/Base.mjs +146 -142
- package/src/worker/Data.mjs +1 -1
package/apps/ServiceWorker.mjs
CHANGED
package/package.json
CHANGED
package/src/DefaultConfig.mjs
CHANGED
@@ -260,12 +260,12 @@ const DefaultConfig = {
|
|
260
260
|
useVdomWorker: true,
|
261
261
|
/**
|
262
262
|
* buildScripts/injectPackageVersion.mjs will update this value
|
263
|
-
* @default '6.15.
|
263
|
+
* @default '6.15.8'
|
264
264
|
* @memberOf! module:Neo
|
265
265
|
* @name config.version
|
266
266
|
* @type String
|
267
267
|
*/
|
268
|
-
version: '6.15.
|
268
|
+
version: '6.15.8'
|
269
269
|
};
|
270
270
|
|
271
271
|
Object.assign(DefaultConfig, {
|
package/src/collection/Base.mjs
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
import CoreBase from '../core/Base.mjs';
|
2
2
|
import Filter from './Filter.mjs';
|
3
3
|
import Logger from '../util/Logger.mjs';
|
4
|
-
import Sorter from './Sorter.mjs';
|
5
4
|
import Observable from '../core/Observable.mjs';
|
6
|
-
import
|
5
|
+
import Sorter from './Sorter.mjs';
|
7
6
|
|
8
7
|
const countMutations = Symbol('countMutations'),
|
9
8
|
isFiltered = Symbol('isFiltered'),
|
@@ -125,7 +124,7 @@ class Base extends CoreBase {
|
|
125
124
|
});
|
126
125
|
|
127
126
|
if (me.autoSort && me._sorters.length > 0) {
|
128
|
-
me.doSort()
|
127
|
+
me.doSort()
|
129
128
|
}
|
130
129
|
}
|
131
130
|
|
@@ -135,7 +134,7 @@ class Base extends CoreBase {
|
|
135
134
|
* @returns {Object[]} an array containing all added items
|
136
135
|
*/
|
137
136
|
add(item) {
|
138
|
-
return this.splice(0, null, item).addedItems
|
137
|
+
return this.splice(0, null, item).addedItems
|
139
138
|
}
|
140
139
|
|
141
140
|
/**
|
@@ -149,11 +148,11 @@ class Base extends CoreBase {
|
|
149
148
|
value.forEach(filter => {
|
150
149
|
if (filter.listenerApplied === false) {
|
151
150
|
filter.on('change', me.onFilterChange, me);
|
152
|
-
filter.listenerApplied = true
|
151
|
+
filter.listenerApplied = true
|
153
152
|
}
|
154
153
|
});
|
155
154
|
|
156
|
-
oldValue && me.filter()
|
155
|
+
oldValue && me.filter()
|
157
156
|
}
|
158
157
|
|
159
158
|
/**
|
@@ -171,7 +170,7 @@ class Base extends CoreBase {
|
|
171
170
|
|
172
171
|
for (; i < len; i++) {
|
173
172
|
item = value[i];
|
174
|
-
me.map.set(item[keyProperty], item)
|
173
|
+
me.map.set(item[keyProperty], item)
|
175
174
|
}
|
176
175
|
}
|
177
176
|
}
|
@@ -189,11 +188,11 @@ class Base extends CoreBase {
|
|
189
188
|
value.forEach(sorter => {
|
190
189
|
if (sorter.listenerApplied === false) {
|
191
190
|
sorter.on('change', me.onSorterChange, me);
|
192
|
-
sorter.listenerApplied = true
|
191
|
+
sorter.listenerApplied = true
|
193
192
|
}
|
194
193
|
});
|
195
194
|
|
196
|
-
oldValue && me.autoSort && me.doSort()
|
195
|
+
oldValue && me.autoSort && me.doSort()
|
197
196
|
}
|
198
197
|
|
199
198
|
/**
|
@@ -216,11 +215,9 @@ class Base extends CoreBase {
|
|
216
215
|
|
217
216
|
source.on(listenersConfig);
|
218
217
|
|
219
|
-
// console.log('afterSetSourceId', source);
|
220
|
-
|
221
218
|
if (oldValue) {
|
222
219
|
source = Neo.get(oldValue);
|
223
|
-
source.un(listenersConfig)
|
220
|
+
source.un(listenersConfig)
|
224
221
|
}
|
225
222
|
}
|
226
223
|
}
|
@@ -237,8 +234,8 @@ class Base extends CoreBase {
|
|
237
234
|
|
238
235
|
me.sorters.forEach(sorter => {//console.log('forEach', sorter);
|
239
236
|
me.sortDirections.push(sorter.directionMultiplier);
|
240
|
-
me.sortProperties.push(sorter.property)
|
241
|
-
})
|
237
|
+
me.sortProperties.push(sorter.property)
|
238
|
+
})
|
242
239
|
}
|
243
240
|
|
244
241
|
/**
|
@@ -248,7 +245,7 @@ class Base extends CoreBase {
|
|
248
245
|
*/
|
249
246
|
beforeSetFilters(value, oldValue) {
|
250
247
|
if (!Array.isArray(value)) {
|
251
|
-
value = value ? [value] : []
|
248
|
+
value = value ? [value] : []
|
252
249
|
}
|
253
250
|
|
254
251
|
let len = oldValue && oldValue.length || 0,
|
@@ -268,34 +265,34 @@ class Base extends CoreBase {
|
|
268
265
|
});
|
269
266
|
|
270
267
|
hasMatch = true;
|
271
|
-
break
|
268
|
+
break
|
272
269
|
} else if (
|
273
270
|
oldValue[i].operator === (key.operator || '===') &&
|
274
271
|
oldValue[i].property === key.property &&
|
275
272
|
oldValue[i].value === key.value
|
276
273
|
) {
|
277
274
|
hasMatch = true;
|
278
|
-
break
|
275
|
+
break
|
279
276
|
}
|
280
277
|
}
|
281
278
|
}
|
282
279
|
|
283
280
|
if (!hasMatch) {
|
284
|
-
value[index] = Neo.create(Filter, key)
|
281
|
+
value[index] = Neo.create(Filter, key)
|
285
282
|
} else {
|
286
283
|
value[index] = oldValue[i];
|
287
284
|
oldValue.splice(i, 1);
|
288
|
-
len
|
285
|
+
len--
|
289
286
|
}
|
290
287
|
});
|
291
288
|
|
292
289
|
if (Array.isArray(oldValue)) {
|
293
290
|
oldValue.forEach(key => {
|
294
291
|
key.destroy();
|
295
|
-
})
|
292
|
+
})
|
296
293
|
}
|
297
294
|
|
298
|
-
return value
|
295
|
+
return value
|
299
296
|
}
|
300
297
|
|
301
298
|
/**
|
@@ -304,7 +301,7 @@ class Base extends CoreBase {
|
|
304
301
|
* @protected
|
305
302
|
*/
|
306
303
|
beforeSetMap(value, oldValue) {
|
307
|
-
return !value ? new Map() : value
|
304
|
+
return !value ? new Map() : value
|
308
305
|
}
|
309
306
|
|
310
307
|
/**
|
@@ -314,7 +311,7 @@ class Base extends CoreBase {
|
|
314
311
|
*/
|
315
312
|
beforeSetSorters(value, oldValue) {
|
316
313
|
if (!Array.isArray(value)) {
|
317
|
-
value = value ? [value] : []
|
314
|
+
value = value ? [value] : []
|
318
315
|
}
|
319
316
|
|
320
317
|
let len = oldValue?.length || 0,
|
@@ -333,28 +330,28 @@ class Base extends CoreBase {
|
|
333
330
|
});
|
334
331
|
|
335
332
|
hasMatch = true;
|
336
|
-
break
|
333
|
+
break
|
337
334
|
} else if (oldValue[i].property === key.property && oldValue[i].direction === key.direction) {
|
338
335
|
hasMatch = true;
|
339
|
-
break
|
336
|
+
break
|
340
337
|
}
|
341
338
|
}
|
342
339
|
}
|
343
340
|
|
344
341
|
if (!hasMatch) {
|
345
|
-
value[index] = Neo.create(Sorter, key)
|
342
|
+
value[index] = Neo.create(Sorter, key)
|
346
343
|
} else {
|
347
344
|
value[index] = oldValue[i];
|
348
345
|
oldValue.splice(i, 1);
|
349
|
-
len
|
346
|
+
len--
|
350
347
|
}
|
351
348
|
});
|
352
349
|
|
353
350
|
oldValue?.forEach(key => {
|
354
|
-
key.destroy()
|
351
|
+
key.destroy()
|
355
352
|
});
|
356
353
|
|
357
|
-
return value
|
354
|
+
return value
|
358
355
|
}
|
359
356
|
|
360
357
|
/**
|
@@ -375,19 +372,19 @@ class Base extends CoreBase {
|
|
375
372
|
|
376
373
|
opts.addedItems.forEach(item => {
|
377
374
|
if (index = toRemoveMap.indexOf(item[keyProperty]) > - 1) {
|
378
|
-
me[toRemoveArray].splice(index, 1)
|
375
|
+
me[toRemoveArray].splice(index, 1)
|
379
376
|
} else if (toAddMap.indexOf(item[keyProperty]) < 0) {
|
380
|
-
me[toAddArray].push(item)
|
377
|
+
me[toAddArray].push(item)
|
381
378
|
}
|
382
379
|
});
|
383
380
|
|
384
381
|
opts.removedItems.forEach(item => {
|
385
382
|
if (index = toAddMap.indexOf(item[keyProperty]) > - 1) {
|
386
|
-
me[toAddArray].splice(index, 1)
|
383
|
+
me[toAddArray].splice(index, 1)
|
387
384
|
} else if (toRemoveMap.indexOf(item[keyProperty]) < 0) {
|
388
|
-
me[toRemoveArray].push(item)
|
385
|
+
me[toRemoveArray].push(item)
|
389
386
|
}
|
390
|
-
})
|
387
|
+
})
|
391
388
|
}
|
392
389
|
}
|
393
390
|
|
@@ -395,7 +392,7 @@ class Base extends CoreBase {
|
|
395
392
|
* Removes all items and clears the map
|
396
393
|
*/
|
397
394
|
clear() {
|
398
|
-
this.splice(0, this.getCount())
|
395
|
+
this.splice(0, this.getCount())
|
399
396
|
}
|
400
397
|
|
401
398
|
/**
|
@@ -403,7 +400,7 @@ class Base extends CoreBase {
|
|
403
400
|
* @param {boolean} [restoreOriginalFilters=false]
|
404
401
|
*/
|
405
402
|
clearFilters(restoreOriginalFilters) {
|
406
|
-
this.filters = restoreOriginalFilters ? Neo.clone(this.originalConfig.filters, true, true) : null
|
403
|
+
this.filters = restoreOriginalFilters ? Neo.clone(this.originalConfig.filters, true, true) : null
|
407
404
|
}
|
408
405
|
|
409
406
|
/**
|
@@ -413,7 +410,7 @@ class Base extends CoreBase {
|
|
413
410
|
let me = this;
|
414
411
|
|
415
412
|
me._items.splice(0, me.getCount());
|
416
|
-
me.map.clear()
|
413
|
+
me.map.clear()
|
417
414
|
}
|
418
415
|
|
419
416
|
/**
|
@@ -422,7 +419,7 @@ class Base extends CoreBase {
|
|
422
419
|
* @param {boolean} [restoreOriginalSorters=false]
|
423
420
|
*/
|
424
421
|
clearSorters(restoreOriginalSorters) {
|
425
|
-
this.sorters = restoreOriginalSorters ? Neo.clone(this.originalConfig.sorters, true, true) : null
|
422
|
+
this.sorters = restoreOriginalSorters ? Neo.clone(this.originalConfig.sorters, true, true) : null
|
426
423
|
}
|
427
424
|
|
428
425
|
/**
|
@@ -440,7 +437,7 @@ class Base extends CoreBase {
|
|
440
437
|
delete config.sorters;
|
441
438
|
|
442
439
|
if (me._items.length > 0) {
|
443
|
-
config.items = [...me._items]
|
440
|
+
config.items = [...me._items]
|
444
441
|
}
|
445
442
|
|
446
443
|
config.filters = [];
|
@@ -449,14 +446,14 @@ class Base extends CoreBase {
|
|
449
446
|
// todo: filters & sorters should push their current state and not the original one
|
450
447
|
|
451
448
|
filters.forEach(function(filter) {
|
452
|
-
config.filters.push(filter.originalConfig)
|
449
|
+
config.filters.push(filter.originalConfig)
|
453
450
|
});
|
454
451
|
|
455
452
|
sorters.forEach(function(sorter) {
|
456
|
-
config.sorters.push(sorter.originalConfig)
|
453
|
+
config.sorters.push(sorter.originalConfig)
|
457
454
|
});
|
458
455
|
|
459
|
-
return Neo.create(Base, config)
|
456
|
+
return Neo.create(Base, config)
|
460
457
|
}
|
461
458
|
|
462
459
|
/**
|
@@ -468,7 +465,7 @@ class Base extends CoreBase {
|
|
468
465
|
me._items.splice(0, me._items.length);
|
469
466
|
me.map.clear();
|
470
467
|
|
471
|
-
super.destroy()
|
468
|
+
super.destroy()
|
472
469
|
}
|
473
470
|
|
474
471
|
/**
|
@@ -491,11 +488,11 @@ class Base extends CoreBase {
|
|
491
488
|
if (countSorters > 0) {
|
492
489
|
sorters.forEach(key => {
|
493
490
|
if (key.sortBy) {
|
494
|
-
hasSortByMethod = true
|
491
|
+
hasSortByMethod = true
|
495
492
|
}
|
496
493
|
|
497
494
|
if (key.useTransformValue) {
|
498
|
-
hasTransformValue = true
|
495
|
+
hasTransformValue = true
|
499
496
|
}
|
500
497
|
});
|
501
498
|
|
@@ -508,11 +505,11 @@ class Base extends CoreBase {
|
|
508
505
|
sortValue = sorter[sorter.sortBy ? 'sortBy' : 'defaultSortBy'](a, b);
|
509
506
|
|
510
507
|
if (sortValue !== 0) {
|
511
|
-
return sortValue
|
508
|
+
return sortValue
|
512
509
|
}
|
513
510
|
}
|
514
511
|
|
515
|
-
return 0
|
512
|
+
return 0
|
516
513
|
});
|
517
514
|
} else {
|
518
515
|
if (hasTransformValue) {
|
@@ -523,16 +520,16 @@ class Base extends CoreBase {
|
|
523
520
|
|
524
521
|
for (; i < countSorters; i++) {
|
525
522
|
if (sorters[i].useTransformValue) {
|
526
|
-
obj[sortProperties[i]] = sorters[i].transformValue(item[sortProperties[i]])
|
523
|
+
obj[sortProperties[i]] = sorters[i].transformValue(item[sortProperties[i]])
|
527
524
|
} else {
|
528
|
-
obj[sortProperties[i]] = item[sortProperties[i]]
|
525
|
+
obj[sortProperties[i]] = item[sortProperties[i]]
|
529
526
|
}
|
530
527
|
}
|
531
528
|
|
532
|
-
return obj
|
529
|
+
return obj
|
533
530
|
});
|
534
531
|
} else {
|
535
|
-
mappedItems = items
|
532
|
+
mappedItems = items
|
536
533
|
}
|
537
534
|
|
538
535
|
mappedItems.sort((a, b) => {
|
@@ -542,21 +539,21 @@ class Base extends CoreBase {
|
|
542
539
|
sortProperty = sortProperties[i];
|
543
540
|
|
544
541
|
if (a[sortProperty] > b[sortProperty]) {
|
545
|
-
return 1 * sortDirections[i]
|
542
|
+
return 1 * sortDirections[i]
|
546
543
|
}
|
547
544
|
|
548
545
|
if (a[sortProperty] < b[sortProperty]) {
|
549
|
-
return -1 * sortDirections[i]
|
546
|
+
return -1 * sortDirections[i]
|
550
547
|
}
|
551
548
|
}
|
552
549
|
|
553
|
-
return 0
|
550
|
+
return 0
|
554
551
|
});
|
555
552
|
|
556
553
|
if (hasTransformValue) {
|
557
554
|
me._items = mappedItems.map(el => {
|
558
|
-
return items[el.index]
|
559
|
-
})
|
555
|
+
return items[el.index]
|
556
|
+
})
|
560
557
|
}
|
561
558
|
}
|
562
559
|
}
|
@@ -568,7 +565,7 @@ class Base extends CoreBase {
|
|
568
565
|
items: me._items,
|
569
566
|
previousItems,
|
570
567
|
scope: me
|
571
|
-
})
|
568
|
+
})
|
572
569
|
}
|
573
570
|
}
|
574
571
|
|
@@ -584,11 +581,11 @@ class Base extends CoreBase {
|
|
584
581
|
const me = this;
|
585
582
|
|
586
583
|
if (me[updatingIndex] > 0) {
|
587
|
-
me[updatingIndex]
|
584
|
+
me[updatingIndex]--
|
588
585
|
}
|
589
586
|
|
590
587
|
if (endSilentUpdateMode) {
|
591
|
-
me[silentUpdateMode] = false
|
588
|
+
me[silentUpdateMode] = false
|
592
589
|
} else {
|
593
590
|
me.fire('mutate', {
|
594
591
|
addedItems : me[toAddArray],
|
@@ -596,7 +593,7 @@ class Base extends CoreBase {
|
|
596
593
|
});
|
597
594
|
|
598
595
|
me[toAddArray] .splice(0, me[toAddArray] .length);
|
599
|
-
me[toRemoveArray].splice(0, me[toRemoveArray].length)
|
596
|
+
me[toRemoveArray].splice(0, me[toRemoveArray].length)
|
600
597
|
}
|
601
598
|
}
|
602
599
|
|
@@ -612,10 +609,10 @@ class Base extends CoreBase {
|
|
612
609
|
me.filters?.forEach(key => {
|
613
610
|
filter = key.export();
|
614
611
|
|
615
|
-
filter && filters.push(filter)
|
612
|
+
filter && filters.push(filter)
|
616
613
|
});
|
617
614
|
|
618
|
-
return filters
|
615
|
+
return filters
|
619
616
|
}
|
620
617
|
|
621
618
|
/**
|
@@ -630,10 +627,10 @@ class Base extends CoreBase {
|
|
630
627
|
me.sorters?.forEach(key => {
|
631
628
|
sorter = key.export();
|
632
629
|
|
633
|
-
sorter && sorters.push(sorter)
|
630
|
+
sorter && sorters.push(sorter)
|
634
631
|
});
|
635
632
|
|
636
|
-
return sorters
|
633
|
+
return sorters
|
637
634
|
}
|
638
635
|
|
639
636
|
/**
|
@@ -654,18 +651,18 @@ class Base extends CoreBase {
|
|
654
651
|
|
655
652
|
for (; i < countAllFilters; i++) {
|
656
653
|
if (!filters[i].disabled) {
|
657
|
-
countFilters
|
654
|
+
countFilters++
|
658
655
|
}
|
659
656
|
}
|
660
657
|
|
661
658
|
if (countFilters === 0 && me.allItems) {
|
662
659
|
if (me.sorters.length > 0) {
|
663
|
-
needsSorting = true
|
660
|
+
needsSorting = true
|
664
661
|
}
|
665
662
|
|
666
663
|
me.clearSilent();
|
667
664
|
|
668
|
-
me.items = [...me.allItems._items]
|
665
|
+
me.items = [...me.allItems._items]
|
669
666
|
} else {
|
670
667
|
if (!me.allItems) {
|
671
668
|
config = {...me.originalConfig};
|
@@ -678,9 +675,7 @@ class Base extends CoreBase {
|
|
678
675
|
...Neo.clone(config, true, true),
|
679
676
|
keyProperty: me.keyProperty,
|
680
677
|
sourceId : me.id
|
681
|
-
})
|
682
|
-
|
683
|
-
// console.log('child collection', me.allItems);
|
678
|
+
})
|
684
679
|
}
|
685
680
|
|
686
681
|
me.map.clear();
|
@@ -695,17 +690,17 @@ class Base extends CoreBase {
|
|
695
690
|
for (; j < countAllFilters; j++) {
|
696
691
|
if (filters[j].isFiltered(item, items, items)) {
|
697
692
|
isIncluded = false;
|
698
|
-
break
|
693
|
+
break
|
699
694
|
}
|
700
695
|
}
|
701
696
|
|
702
697
|
if (isIncluded) {
|
703
698
|
filteredItems.push(item);
|
704
|
-
me.map.set(item[me.keyProperty], item)
|
699
|
+
me.map.set(item[me.keyProperty], item)
|
705
700
|
}
|
706
701
|
}
|
707
702
|
|
708
|
-
me._items = filteredItems
|
703
|
+
me._items = filteredItems // silent update, the map is already in place
|
709
704
|
} else {
|
710
705
|
filteredItems = [...items];
|
711
706
|
|
@@ -714,22 +709,22 @@ class Base extends CoreBase {
|
|
714
709
|
|
715
710
|
for (i = 0; i < countItems; i++) {
|
716
711
|
if (!filters[j].isFiltered(filteredItems[i], filteredItems, items)) {
|
717
|
-
tmpItems.push(filteredItems[i])
|
712
|
+
tmpItems.push(filteredItems[i])
|
718
713
|
}
|
719
714
|
}
|
720
715
|
|
721
716
|
filteredItems = [...tmpItems];
|
722
|
-
countItems = filteredItems.length
|
717
|
+
countItems = filteredItems.length
|
723
718
|
}
|
724
719
|
|
725
|
-
me.items = filteredItems
|
720
|
+
me.items = filteredItems // update the map
|
726
721
|
}
|
727
722
|
}
|
728
723
|
|
729
724
|
me[isFiltered] = countFilters !== 0;
|
730
725
|
|
731
726
|
if (needsSorting) {
|
732
|
-
me.doSort(me.items, true)
|
727
|
+
me.doSort(me.items, true)
|
733
728
|
}
|
734
729
|
|
735
730
|
me.fire('filter', {
|
@@ -737,7 +732,7 @@ class Base extends CoreBase {
|
|
737
732
|
items : me.items,
|
738
733
|
oldItems,
|
739
734
|
scope : me
|
740
|
-
})
|
735
|
+
})
|
741
736
|
}
|
742
737
|
|
743
738
|
/**
|
@@ -752,7 +747,7 @@ class Base extends CoreBase {
|
|
752
747
|
find(property, value, returnFirstMatch=false) {
|
753
748
|
let me = this,
|
754
749
|
items = [],
|
755
|
-
isObjectProperty =
|
750
|
+
isObjectProperty = me.isItem(property),
|
756
751
|
item, matchArray, propertiesArray, propertiesLength;
|
757
752
|
|
758
753
|
if (isObjectProperty) {
|
@@ -766,27 +761,27 @@ class Base extends CoreBase {
|
|
766
761
|
|
767
762
|
propertiesArray.forEach(([key, value]) => {
|
768
763
|
if (item[key] === value) {
|
769
|
-
matchArray.push(true)
|
764
|
+
matchArray.push(true)
|
770
765
|
}
|
771
766
|
});
|
772
767
|
|
773
768
|
if (matchArray.length === propertiesLength) {
|
774
769
|
if (returnFirstMatch) {
|
775
|
-
return item
|
770
|
+
return item
|
776
771
|
}
|
777
772
|
|
778
|
-
items.push(item)
|
773
|
+
items.push(item)
|
779
774
|
}
|
780
775
|
} else if (item[property] === value) {
|
781
776
|
if (returnFirstMatch) {
|
782
|
-
return item
|
777
|
+
return item
|
783
778
|
}
|
784
779
|
|
785
|
-
items.push(item)
|
780
|
+
items.push(item)
|
786
781
|
}
|
787
782
|
}
|
788
783
|
|
789
|
-
return returnFirstMatch ? null : items
|
784
|
+
return returnFirstMatch ? null : items
|
790
785
|
}
|
791
786
|
|
792
787
|
/**
|
@@ -805,11 +800,11 @@ class Base extends CoreBase {
|
|
805
800
|
|
806
801
|
for (; i < end; i++) {
|
807
802
|
if (fn.call(scope, me.items[i])) {
|
808
|
-
items.push(me.items[i])
|
803
|
+
items.push(me.items[i])
|
809
804
|
}
|
810
805
|
}
|
811
806
|
|
812
|
-
return items
|
807
|
+
return items
|
813
808
|
}
|
814
809
|
|
815
810
|
/**
|
@@ -819,7 +814,7 @@ class Base extends CoreBase {
|
|
819
814
|
* @returns {Object} Returns the first found item or null
|
820
815
|
*/
|
821
816
|
findFirst(property, value) {
|
822
|
-
return this.find(property, value, true)
|
817
|
+
return this.find(property, value, true)
|
823
818
|
}
|
824
819
|
|
825
820
|
/**
|
@@ -827,7 +822,7 @@ class Base extends CoreBase {
|
|
827
822
|
* @returns {Object}
|
828
823
|
*/
|
829
824
|
first() {
|
830
|
-
return this._items[0]
|
825
|
+
return this._items[0]
|
831
826
|
}
|
832
827
|
|
833
828
|
/**
|
@@ -845,7 +840,7 @@ class Base extends CoreBase {
|
|
845
840
|
* @returns {Object|undefined}
|
846
841
|
*/
|
847
842
|
getAt(index) {
|
848
|
-
return this._items[index]
|
843
|
+
return this._items[index]
|
849
844
|
}
|
850
845
|
|
851
846
|
/**
|
@@ -853,14 +848,14 @@ class Base extends CoreBase {
|
|
853
848
|
* @returns {Number}
|
854
849
|
*/
|
855
850
|
getCount() {
|
856
|
-
return this._items.length
|
851
|
+
return this._items.length
|
857
852
|
}
|
858
853
|
|
859
854
|
/**
|
860
855
|
* @returns {Number}
|
861
856
|
*/
|
862
857
|
getCountMutations() {
|
863
|
-
return this[countMutations]
|
858
|
+
return this[countMutations]
|
864
859
|
}
|
865
860
|
|
866
861
|
/**
|
@@ -875,11 +870,11 @@ class Base extends CoreBase {
|
|
875
870
|
|
876
871
|
for (; i < len; i++) {
|
877
872
|
if (filters[i].property === property) {
|
878
|
-
return filters[i]
|
873
|
+
return filters[i]
|
879
874
|
}
|
880
875
|
}
|
881
876
|
|
882
|
-
return null
|
877
|
+
return null
|
883
878
|
}
|
884
879
|
|
885
880
|
/**
|
@@ -889,7 +884,7 @@ class Base extends CoreBase {
|
|
889
884
|
*/
|
890
885
|
getKeyAt(index) {
|
891
886
|
let item = this._items[index];
|
892
|
-
return item?.[this.keyProperty]
|
887
|
+
return item?.[this.keyProperty]
|
893
888
|
}
|
894
889
|
|
895
890
|
/**
|
@@ -900,7 +895,7 @@ class Base extends CoreBase {
|
|
900
895
|
* @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
|
901
896
|
*/
|
902
897
|
getRange(start, end) {
|
903
|
-
return this._items.slice(start, end)
|
898
|
+
return this._items.slice(start, end)
|
904
899
|
}
|
905
900
|
|
906
901
|
/**
|
@@ -908,7 +903,7 @@ class Base extends CoreBase {
|
|
908
903
|
* @returns {Neo.collection.Base|undefined}
|
909
904
|
*/
|
910
905
|
getSource() {
|
911
|
-
return this.sourceId && Neo.get(this.sourceId)
|
906
|
+
return this.sourceId && Neo.get(this.sourceId)
|
912
907
|
}
|
913
908
|
|
914
909
|
/**
|
@@ -917,7 +912,7 @@ class Base extends CoreBase {
|
|
917
912
|
* @returns {Boolean}
|
918
913
|
*/
|
919
914
|
has(key) {
|
920
|
-
return this.map.has(key)
|
915
|
+
return this.map.has(key)
|
921
916
|
}
|
922
917
|
|
923
918
|
/**
|
@@ -926,7 +921,7 @@ class Base extends CoreBase {
|
|
926
921
|
* @returns {Boolean}
|
927
922
|
*/
|
928
923
|
hasItem(item) {
|
929
|
-
return this.map.has(item[this.keyProperty])
|
924
|
+
return this.map.has(item[this.keyProperty])
|
930
925
|
}
|
931
926
|
|
932
927
|
/**
|
@@ -935,7 +930,8 @@ class Base extends CoreBase {
|
|
935
930
|
* @returns {Number} index (-1 in case no match is found)
|
936
931
|
*/
|
937
932
|
indexOf(key) {
|
938
|
-
|
933
|
+
let me = this;
|
934
|
+
return me._items.indexOf(me.isItem(key) ? key : me.map.get(key))
|
939
935
|
}
|
940
936
|
|
941
937
|
/**
|
@@ -944,7 +940,7 @@ class Base extends CoreBase {
|
|
944
940
|
* @returns {Number} index (-1 in case no match is found)
|
945
941
|
*/
|
946
942
|
indexOfItem(item) {
|
947
|
-
return this._items.indexOf(item)
|
943
|
+
return this._items.indexOf(item)
|
948
944
|
}
|
949
945
|
|
950
946
|
/**
|
@@ -953,7 +949,7 @@ class Base extends CoreBase {
|
|
953
949
|
* @returns {Number} index (-1 in case no match is found)
|
954
950
|
*/
|
955
951
|
indexOfKey(key) {
|
956
|
-
return this._items.indexOf(this.map.get(key))
|
952
|
+
return this._items.indexOf(this.map.get(key))
|
957
953
|
}
|
958
954
|
|
959
955
|
/**
|
@@ -963,14 +959,14 @@ class Base extends CoreBase {
|
|
963
959
|
* @returns {Object[]} an array containing all added items
|
964
960
|
*/
|
965
961
|
insert(index, item) {
|
966
|
-
return this.splice(index, 0, item).addedItems
|
962
|
+
return this.splice(index, 0, item).addedItems
|
967
963
|
}
|
968
964
|
|
969
965
|
/**
|
970
966
|
* @returns {Boolean} true in case the collection is filtered
|
971
967
|
*/
|
972
968
|
isFiltered() {
|
973
|
-
return this[isFiltered]
|
969
|
+
return this[isFiltered]
|
974
970
|
}
|
975
971
|
|
976
972
|
/**
|
@@ -988,18 +984,27 @@ class Base extends CoreBase {
|
|
988
984
|
for (; i < len; i++) {
|
989
985
|
if (filters[i].isFiltered(item)) {
|
990
986
|
isFiltered = true;
|
991
|
-
break
|
987
|
+
break
|
992
988
|
}
|
993
989
|
}
|
994
990
|
|
995
|
-
return isFiltered
|
991
|
+
return isFiltered
|
992
|
+
}
|
993
|
+
|
994
|
+
/**
|
995
|
+
* Helper method to check if a given value is either an object or a neo data record
|
996
|
+
* @param {*} value
|
997
|
+
* @returns {Boolean}
|
998
|
+
*/
|
999
|
+
isItem(value) {
|
1000
|
+
return Neo.isObject(value) || Neo.isRecord(value)
|
996
1001
|
}
|
997
1002
|
|
998
1003
|
/**
|
999
1004
|
* @returns {Boolean} true in case the collection is sorted
|
1000
1005
|
*/
|
1001
1006
|
isSorted() {
|
1002
|
-
return this[isSorted]
|
1007
|
+
return this[isSorted]
|
1003
1008
|
}
|
1004
1009
|
|
1005
1010
|
/**
|
@@ -1007,7 +1012,7 @@ class Base extends CoreBase {
|
|
1007
1012
|
* @returns {Object}
|
1008
1013
|
*/
|
1009
1014
|
last() {
|
1010
|
-
return this._items[this.getCount() -1]
|
1015
|
+
return this._items[this.getCount() -1]
|
1011
1016
|
}
|
1012
1017
|
|
1013
1018
|
/**
|
@@ -1015,7 +1020,7 @@ class Base extends CoreBase {
|
|
1015
1020
|
* @protected
|
1016
1021
|
*/
|
1017
1022
|
onFilterChange(opts) {
|
1018
|
-
this.filter()
|
1023
|
+
this.filter()
|
1019
1024
|
}
|
1020
1025
|
|
1021
1026
|
/**
|
@@ -1026,10 +1031,10 @@ class Base extends CoreBase {
|
|
1026
1031
|
let me = this;
|
1027
1032
|
|
1028
1033
|
if (opts.preventBubbleUp) {
|
1029
|
-
me.preventBubbleUp = true
|
1034
|
+
me.preventBubbleUp = true
|
1030
1035
|
}
|
1031
1036
|
|
1032
|
-
me.splice(null, opts.removedItems, opts.addedItems)
|
1037
|
+
me.splice(null, opts.removedItems, opts.addedItems)
|
1033
1038
|
}
|
1034
1039
|
|
1035
1040
|
/**
|
@@ -1038,7 +1043,7 @@ class Base extends CoreBase {
|
|
1038
1043
|
*/
|
1039
1044
|
onSorterChange(opts) {
|
1040
1045
|
this.applySorterConfigs();
|
1041
|
-
this.doSort()
|
1046
|
+
this.doSort()
|
1042
1047
|
}
|
1043
1048
|
|
1044
1049
|
/**
|
@@ -1047,7 +1052,7 @@ class Base extends CoreBase {
|
|
1047
1052
|
*/
|
1048
1053
|
pop() {
|
1049
1054
|
let mutation = this.splice(this.getCount() -1, 1);
|
1050
|
-
return mutation.removedItems[0]
|
1055
|
+
return mutation.removedItems[0]
|
1051
1056
|
}
|
1052
1057
|
|
1053
1058
|
/**
|
@@ -1056,7 +1061,7 @@ class Base extends CoreBase {
|
|
1056
1061
|
* @returns {Number} the collection count
|
1057
1062
|
*/
|
1058
1063
|
push(item) {
|
1059
|
-
return this.add(item)
|
1064
|
+
return this.add(item)
|
1060
1065
|
}
|
1061
1066
|
|
1062
1067
|
/**
|
@@ -1066,7 +1071,7 @@ class Base extends CoreBase {
|
|
1066
1071
|
*/
|
1067
1072
|
remove(key) {
|
1068
1073
|
this.splice(0, Array.isArray(key) ? key : [key]);
|
1069
|
-
return this.getCount()
|
1074
|
+
return this.getCount()
|
1070
1075
|
}
|
1071
1076
|
|
1072
1077
|
/**
|
@@ -1076,7 +1081,7 @@ class Base extends CoreBase {
|
|
1076
1081
|
*/
|
1077
1082
|
removeAt(index) {
|
1078
1083
|
this.splice(index, 1);
|
1079
|
-
return this.getCount()
|
1084
|
+
return this.getCount()
|
1080
1085
|
}
|
1081
1086
|
|
1082
1087
|
/**
|
@@ -1085,7 +1090,7 @@ class Base extends CoreBase {
|
|
1085
1090
|
* @returns {Array} items
|
1086
1091
|
*/
|
1087
1092
|
reverse() {
|
1088
|
-
return this._items.reverse()
|
1093
|
+
return this._items.reverse()
|
1089
1094
|
}
|
1090
1095
|
|
1091
1096
|
/**
|
@@ -1094,7 +1099,7 @@ class Base extends CoreBase {
|
|
1094
1099
|
*/
|
1095
1100
|
shift() {
|
1096
1101
|
let mutation = this.splice(0, 1);
|
1097
|
-
return mutation.addedItems[0]
|
1102
|
+
return mutation.addedItems[0]
|
1098
1103
|
}
|
1099
1104
|
|
1100
1105
|
/**
|
@@ -1107,7 +1112,7 @@ class Base extends CoreBase {
|
|
1107
1112
|
* @returns {boolean} true if the callback function returns a truthy value for any collection item, otherwise false
|
1108
1113
|
*/
|
1109
1114
|
some(...args) {
|
1110
|
-
return this._items.some(...args)
|
1115
|
+
return this._items.some(...args)
|
1111
1116
|
}
|
1112
1117
|
|
1113
1118
|
/**
|
@@ -1127,37 +1132,37 @@ class Base extends CoreBase {
|
|
1127
1132
|
keyProperty = me.keyProperty,
|
1128
1133
|
map = me.map,
|
1129
1134
|
removedItems = [],
|
1130
|
-
removeCountAtIndex =
|
1135
|
+
removeCountAtIndex = Neo.isNumber(removeCountOrToRemoveArray) ? removeCountOrToRemoveArray : null,
|
1131
1136
|
toRemoveArray = Array.isArray(removeCountOrToRemoveArray) ? removeCountOrToRemoveArray : null,
|
1132
1137
|
i, item, key, len, toAddMap;
|
1133
1138
|
|
1134
|
-
if (!
|
1135
|
-
Logger.error(me.id + ': If index is not passed, removeCountAtIndex cannot be used')
|
1139
|
+
if (!Neo.isNumber(index) && removeCountAtIndex) {
|
1140
|
+
Logger.error(me.id + ': If index is not passed, removeCountAtIndex cannot be used')
|
1136
1141
|
}
|
1137
1142
|
|
1138
1143
|
toAddArray = toAddArray && !Array.isArray(toAddArray) ? [toAddArray] : toAddArray;
|
1139
1144
|
|
1140
1145
|
if (toRemoveArray && (len = toRemoveArray.length) > 0) {
|
1141
1146
|
if (toAddArray && toAddArray.length > 0) {
|
1142
|
-
toAddMap = toAddArray.map(e => e[keyProperty])
|
1147
|
+
toAddMap = toAddArray.map(e => e[keyProperty])
|
1143
1148
|
}
|
1144
1149
|
|
1145
1150
|
for (i=0; i < len; i++) {
|
1146
1151
|
item = toRemoveArray[i];
|
1147
|
-
key =
|
1152
|
+
key = me.isItem(item) ? item[keyProperty] : item;
|
1148
1153
|
|
1149
1154
|
if (map.has(key)) {
|
1150
1155
|
if (!toAddMap || (toAddMap && toAddMap.indexOf(key) < 0)) {
|
1151
1156
|
removedItems.push(items.splice(me.indexOfKey(key), 1)[0]);
|
1152
|
-
map.delete(key)
|
1157
|
+
map.delete(key)
|
1153
1158
|
}
|
1154
1159
|
}
|
1155
1160
|
}
|
1156
1161
|
} else if (removeCountAtIndex && removeCountAtIndex > 0) {
|
1157
1162
|
removedItems.push(...items.splice(index, removeCountAtIndex));
|
1158
1163
|
removedItems.forEach(e => {
|
1159
|
-
map.delete(e[keyProperty])
|
1160
|
-
})
|
1164
|
+
map.delete(e[keyProperty])
|
1165
|
+
})
|
1161
1166
|
}
|
1162
1167
|
|
1163
1168
|
if (toAddArray && (len = toAddArray.length) > 0) {
|
@@ -1167,20 +1172,20 @@ class Base extends CoreBase {
|
|
1167
1172
|
|
1168
1173
|
if (!key) {
|
1169
1174
|
item[keyProperty] = key = me.keyPropertyIndex;
|
1170
|
-
me.keyPropertyIndex
|
1175
|
+
me.keyPropertyIndex--
|
1171
1176
|
}
|
1172
1177
|
|
1173
1178
|
if (!map.has(key) && !me.isFilteredItem(item)) {
|
1174
1179
|
addedItems.push(item);
|
1175
|
-
map.set(key, item)
|
1180
|
+
map.set(key, item)
|
1176
1181
|
}
|
1177
1182
|
}
|
1178
1183
|
|
1179
1184
|
if (addedItems.length > 0) {
|
1180
|
-
items.splice(
|
1185
|
+
items.splice(Neo.isNumber(index) ? index : items.length, 0, ...addedItems);
|
1181
1186
|
|
1182
1187
|
if (me.autoSort && me._sorters.length > 0) {
|
1183
|
-
me.doSort()
|
1188
|
+
me.doSort()
|
1184
1189
|
}
|
1185
1190
|
}
|
1186
1191
|
}
|
@@ -1194,14 +1199,14 @@ class Base extends CoreBase {
|
|
1194
1199
|
// console.log('source splice', source.id, 'added:', ...toAddArray, 'removed:', ...removedItems);
|
1195
1200
|
me.startUpdate(true);
|
1196
1201
|
source.splice(null, toRemoveArray || removedItems, toAddArray);
|
1197
|
-
me.endUpdate(true)
|
1202
|
+
me.endUpdate(true)
|
1198
1203
|
}
|
1199
1204
|
|
1200
|
-
delete source.preventBubbleUp
|
1205
|
+
delete source.preventBubbleUp
|
1201
1206
|
}
|
1202
1207
|
|
1203
1208
|
if (addedItems.length > 0 || removedItems.length > 0) {
|
1204
|
-
me[countMutations]
|
1209
|
+
me[countMutations]++
|
1205
1210
|
}
|
1206
1211
|
|
1207
1212
|
if (me[updatingIndex] === 0) {
|
@@ -1209,23 +1214,22 @@ class Base extends CoreBase {
|
|
1209
1214
|
addedItems : toAddArray,
|
1210
1215
|
preventBubbleUp: me.preventBubbleUp,
|
1211
1216
|
removedItems : toRemoveArray || removedItems
|
1212
|
-
})
|
1213
|
-
|
1217
|
+
})
|
1214
1218
|
} else if (!me[silentUpdateMode]) {
|
1215
1219
|
me.cacheUpdate({
|
1216
1220
|
addedItems,
|
1217
1221
|
removedItems
|
1218
|
-
})
|
1222
|
+
})
|
1219
1223
|
}
|
1220
1224
|
|
1221
1225
|
if (me[updatingIndex] === 0) {
|
1222
|
-
delete me.preventBubbleUp
|
1226
|
+
delete me.preventBubbleUp
|
1223
1227
|
}
|
1224
1228
|
|
1225
1229
|
return {
|
1226
1230
|
addedItems,
|
1227
1231
|
removedItems
|
1228
|
-
}
|
1232
|
+
}
|
1229
1233
|
}
|
1230
1234
|
|
1231
1235
|
/**
|
@@ -1239,10 +1243,10 @@ class Base extends CoreBase {
|
|
1239
1243
|
*/
|
1240
1244
|
startUpdate(startSilentUpdateMode) {
|
1241
1245
|
if (startSilentUpdateMode) {
|
1242
|
-
this[silentUpdateMode] = true
|
1246
|
+
this[silentUpdateMode] = true
|
1243
1247
|
}
|
1244
1248
|
|
1245
|
-
this[updatingIndex]
|
1249
|
+
this[updatingIndex]++
|
1246
1250
|
}
|
1247
1251
|
|
1248
1252
|
/**
|
@@ -1252,7 +1256,7 @@ class Base extends CoreBase {
|
|
1252
1256
|
*/
|
1253
1257
|
unshift(item) {
|
1254
1258
|
this.splice(0, 0, item);
|
1255
|
-
return this.getCount()
|
1259
|
+
return this.getCount()
|
1256
1260
|
}
|
1257
1261
|
}
|
1258
1262
|
|
package/src/worker/Data.mjs
CHANGED
@@ -2,8 +2,8 @@ import Neo from '../Neo.mjs';
|
|
2
2
|
import Base from './Base.mjs';
|
3
3
|
import Compare from '../core/Compare.mjs';
|
4
4
|
import Fetch from '../Fetch.mjs';
|
5
|
-
import StoreManager from '../manager/Store.mjs';
|
6
5
|
import Util from '../core/Util.mjs';
|
6
|
+
import StoreManager from '../manager/Store.mjs';
|
7
7
|
import Xhr from '../Xhr.mjs';
|
8
8
|
|
9
9
|
/**
|