tinybase 0.9.2 → 1.0.1

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * This everything.
2
+ * This is everything.
3
3
  *
4
4
  * @packageDocumentation
5
5
  */
@@ -9,6 +9,5 @@ export * from './common';
9
9
  export * from './indexes';
10
10
  export * from './metrics';
11
11
  export * from './persisters';
12
- export * from './react';
13
12
  export * from './relationships';
14
13
  export * from './store';
@@ -509,6 +509,8 @@ const createCheckpoints = getCreateFunction((store) => {
509
509
  return objFreeze(checkpoints.clear());
510
510
  });
511
511
 
512
+ const defaultSorter = (sortKey1, sortKey2) => (sortKey1 < sortKey2 ? -1 : 1);
513
+
512
514
  const createIndexes = getCreateFunction((store) => {
513
515
  const sliceIdsListeners = mapNew();
514
516
  const sliceRowIdsListeners = mapNew();
@@ -541,7 +543,7 @@ const createIndexes = getCreateFunction((store) => {
541
543
  setDefinition(
542
544
  indexId,
543
545
  tableId,
544
- (change, changedSliceIds, changedSortKeys, sliceIds, sortKeys) => {
546
+ (change, changedSliceIds, changedSortKeys, sliceIds, sortKeys, force) => {
545
547
  let sliceIdsChanged = 0;
546
548
  const changedSlices = setNew();
547
549
  const unsortedSlices = setNew();
@@ -570,12 +572,16 @@ const createIndexes = getCreateFunction((store) => {
570
572
  }
571
573
  });
572
574
  change();
573
- mapForEach(changedSortKeys, (rowId) =>
574
- ifNotUndefined(mapGet(sliceIds, rowId), (sliceId) =>
575
- setAdd(unsortedSlices, sliceId),
576
- ),
577
- );
578
575
  if (!collIsEmpty(sortKeys)) {
576
+ if (force) {
577
+ mapForEach(index, (sliceId) => setAdd(unsortedSlices, sliceId));
578
+ } else {
579
+ mapForEach(changedSortKeys, (rowId) =>
580
+ ifNotUndefined(mapGet(sliceIds, rowId), (sliceId) =>
581
+ setAdd(unsortedSlices, sliceId),
582
+ ),
583
+ );
584
+ }
579
585
  collForEach(unsortedSlices, (sliceId) => {
580
586
  const rowIdArraySorter = (rowId1, rowId2) =>
581
587
  rowIdSorter(
@@ -594,7 +600,7 @@ const createIndexes = getCreateFunction((store) => {
594
600
  }
595
601
  });
596
602
  }
597
- if (sliceIdsChanged) {
603
+ if (sliceIdsChanged || force) {
598
604
  if (!isUndefined(sliceIdArraySorter)) {
599
605
  const indexArray = [...index];
600
606
  if (!arrayIsSorted(indexArray, sliceIdArraySorter)) {
@@ -602,8 +608,11 @@ const createIndexes = getCreateFunction((store) => {
602
608
  indexId,
603
609
  mapNew(arraySort(indexArray, sliceIdArraySorter)),
604
610
  );
611
+ sliceIdsChanged = 1;
605
612
  }
606
613
  }
614
+ }
615
+ if (sliceIdsChanged) {
607
616
  callListeners(sliceIdsListeners, [indexId]);
608
617
  }
609
618
  collForEach(changedSlices, (sliceId) =>
@@ -650,7 +659,6 @@ const createIndexes = getCreateFunction((store) => {
650
659
  };
651
660
  return objFreeze(indexes);
652
661
  });
653
- const defaultSorter = (sortKey1, sortKey2) => (sortKey1 < sortKey2 ? -1 : 1);
654
662
 
655
663
  const aggregators = mapNew([
656
664
  [