@mmstack/primitives 20.0.1 → 20.0.2

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.
@@ -101,7 +101,7 @@ function debounced(initial, opt) {
101
101
  */
102
102
  function debounce(source, opt) {
103
103
  const ms = opt?.ms ?? 0;
104
- const trigger = signal(false);
104
+ const trigger = signal(false, ...(ngDevMode ? [{ debugName: "trigger" }] : []));
105
105
  let timeout;
106
106
  try {
107
107
  const destroyRef = opt?.destroyRef ?? inject(DestroyRef, { optional: true });
@@ -349,7 +349,7 @@ function elementVisibility(target = inject(ElementRef), opt) {
349
349
  const base = computed(() => undefined, {
350
350
  debugName: opt?.debugName,
351
351
  });
352
- base.visible = computed(() => false);
352
+ base.visible = computed(() => false, ...(ngDevMode ? [{ debugName: "visible" }] : []));
353
353
  return base;
354
354
  }
355
355
  const state = signal(undefined, {
@@ -386,7 +386,7 @@ function elementVisibility(target = inject(ElementRef), opt) {
386
386
  if (!s)
387
387
  return false;
388
388
  return s.isIntersecting;
389
- });
389
+ }, ...(ngDevMode ? [{ debugName: "visible" }] : []));
390
390
  return base;
391
391
  }
392
392
 
@@ -451,7 +451,7 @@ function elementVisibility(target = inject(ElementRef), opt) {
451
451
  */
452
452
  function mapArray(source, map, opt) {
453
453
  const data = isSignal(source) ? source : computed(source);
454
- const len = computed(() => data().length);
454
+ const len = computed(() => data().length, ...(ngDevMode ? [{ debugName: "len" }] : []));
455
455
  return linkedSignal({
456
456
  source: () => len(),
457
457
  computation: (len, prev) => {
@@ -460,7 +460,13 @@ function mapArray(source, map, opt) {
460
460
  if (len === prev.value.length)
461
461
  return prev.value;
462
462
  if (len < prev.value.length) {
463
- return prev.value.slice(0, len);
463
+ const slice = prev.value.slice(0, len);
464
+ if (opt?.onDestroy) {
465
+ for (let i = len; i < prev.value.length; i++) {
466
+ opt.onDestroy?.(prev.value[i]);
467
+ }
468
+ }
469
+ return slice;
464
470
  }
465
471
  else {
466
472
  const next = [...prev.value];
@@ -522,7 +528,7 @@ function mediaQuery(query, debugName) {
522
528
  if (isPlatformServer(inject(PLATFORM_ID)))
523
529
  return computed(() => false, { debugName });
524
530
  const mediaQueryList = window.matchMedia(query);
525
- const state = signal(mediaQueryList.matches, { debugName });
531
+ const state = signal(mediaQueryList.matches, ...(ngDevMode ? [{ debugName: "state", debugName }] : [{ debugName }]));
526
532
  const handleChange = (event) => {
527
533
  state.set(event.matches);
528
534
  };
@@ -632,7 +638,7 @@ function throttled(initial, opt) {
632
638
  */
633
639
  function throttle(source, opt) {
634
640
  const ms = opt?.ms ?? 0;
635
- const trigger = signal(false);
641
+ const trigger = signal(false, ...(ngDevMode ? [{ debugName: "trigger" }] : []));
636
642
  let timeout;
637
643
  try {
638
644
  const destroyRef = opt?.destroyRef ?? inject(DestroyRef, { optional: true });
@@ -777,13 +783,13 @@ function networkStatus(debugName) {
777
783
  const sig = computed(() => true, {
778
784
  debugName,
779
785
  });
780
- sig.since = computed(() => serverDate);
786
+ sig.since = computed(() => serverDate, ...(ngDevMode ? [{ debugName: "since" }] : []));
781
787
  return sig;
782
788
  }
783
- const state = signal(navigator.onLine, {
784
- debugName,
785
- });
786
- const since = signal(new Date());
789
+ const state = signal(navigator.onLine, ...(ngDevMode ? [{ debugName: "state", debugName }] : [{
790
+ debugName,
791
+ }]));
792
+ const since = signal(new Date(), ...(ngDevMode ? [{ debugName: "since" }] : []));
787
793
  const goOnline = () => {
788
794
  state.set(true);
789
795
  since.set(new Date());
@@ -843,7 +849,7 @@ function pageVisibility(debugName) {
843
849
  if (isPlatformServer(inject(PLATFORM_ID))) {
844
850
  return computed(() => 'visible', { debugName });
845
851
  }
846
- const visibility = signal(document.visibilityState, { debugName });
852
+ const visibility = signal(document.visibilityState, ...(ngDevMode ? [{ debugName: "visibility", debugName }] : [{ debugName }]));
847
853
  const onVisibilityChange = () => visibility.set(document.visibilityState);
848
854
  document.addEventListener('visibilitychange', onVisibilityChange);
849
855
  inject(DestroyRef).onDestroy(() => document.removeEventListener('visibilitychange', onVisibilityChange));
@@ -1139,16 +1145,23 @@ function stored(fallback, { key, store: providedStore, serialize = JSON.stringif
1139
1145
  equal,
1140
1146
  };
1141
1147
  const initialKey = untracked(keySig);
1142
- const internal = signal(getValue(initialKey), {
1143
- ...opt,
1144
- equal: (a, b) => {
1145
- if (a === null && b === null)
1146
- return true;
1147
- if (a === null || b === null)
1148
- return false;
1149
- return equal(a, b);
1150
- },
1151
- });
1148
+ const internal = signal(getValue(initialKey), ...(ngDevMode ? [{ debugName: "internal", ...opt,
1149
+ equal: (a, b) => {
1150
+ if (a === null && b === null)
1151
+ return true;
1152
+ if (a === null || b === null)
1153
+ return false;
1154
+ return equal(a, b);
1155
+ } }] : [{
1156
+ ...opt,
1157
+ equal: (a, b) => {
1158
+ if (a === null && b === null)
1159
+ return true;
1160
+ if (a === null || b === null)
1161
+ return false;
1162
+ return equal(a, b);
1163
+ },
1164
+ }]));
1152
1165
  let prevKey = initialKey;
1153
1166
  if (onKeyChange === 'store') {
1154
1167
  effect(() => {
@@ -1417,9 +1430,9 @@ function withHistory(source, opt) {
1417
1430
  history.set([]);
1418
1431
  redoArray.set([]);
1419
1432
  };
1420
- internal.canUndo = computed(() => history().length > 0);
1421
- internal.canRedo = computed(() => redoArray().length > 0);
1422
- internal.canClear = computed(() => internal.canUndo() || internal.canRedo());
1433
+ internal.canUndo = computed(() => history().length > 0, ...(ngDevMode ? [{ debugName: "canUndo" }] : []));
1434
+ internal.canRedo = computed(() => redoArray().length > 0, ...(ngDevMode ? [{ debugName: "canRedo" }] : []));
1435
+ internal.canClear = computed(() => internal.canUndo() || internal.canRedo(), ...(ngDevMode ? [{ debugName: "canClear" }] : []));
1423
1436
  return internal;
1424
1437
  }
1425
1438