@mmstack/resource 21.4.4 → 21.4.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.
@@ -2448,13 +2448,17 @@ function mutationResource(request, options0 = {}) {
2448
2448
  return false;
2449
2449
  return eq(a, b);
2450
2450
  } });
2451
- const queue = signal([], ...(ngDevMode ? [{ debugName: "queue" }] : /* istanbul ignore next */ []));
2451
+ const queueEnabled = !!options.queue;
2452
+ const queueKeyFn = typeof options.queue === 'object' ? options.queue.key : undefined;
2453
+ const queue = linkedSignal({ ...(ngDevMode ? { debugName: "queue" } : /* istanbul ignore next */ {}), source: () => queueKeyFn?.(),
2454
+ computation: () => signal([]) });
2452
2455
  let ctx = undefined;
2453
2456
  const queueRef = effect(() => {
2454
- const nextInQueue = queue().at(0);
2457
+ const q = queue(); // subscribe to swaps (key change / clearQueue)
2458
+ const nextInQueue = q().at(0); // subscribe to contents
2455
2459
  if (nextInQueue === undefined || next() !== NULL_VALUE)
2456
2460
  return;
2457
- queue.update((q) => q.slice(1));
2461
+ q.update((arr) => arr.slice(1));
2458
2462
  const [value, ictx] = nextInQueue;
2459
2463
  try {
2460
2464
  ctx = onMutate?.(value, ictx);
@@ -2554,7 +2558,6 @@ function mutationResource(request, options0 = {}) {
2554
2558
  ctx = undefined;
2555
2559
  next.set(NULL_VALUE);
2556
2560
  });
2557
- const shouldQueue = options.queue ?? false;
2558
2561
  const ref = {
2559
2562
  ...resource,
2560
2563
  destroy: () => {
@@ -2564,8 +2567,8 @@ function mutationResource(request, options0 = {}) {
2564
2567
  resource.destroy();
2565
2568
  },
2566
2569
  mutate: (value, ictx) => {
2567
- if (shouldQueue) {
2568
- return queue.update((q) => [...q, [value, ictx]]);
2570
+ if (queueEnabled) {
2571
+ return queue().update((arr) => [...arr, [value, ictx]]);
2569
2572
  }
2570
2573
  else {
2571
2574
  // latest-wins: a mutation already in flight gets superseded (its request is
@@ -2599,6 +2602,11 @@ function mutationResource(request, options0 = {}) {
2599
2602
  const nv = next();
2600
2603
  return nv === NULL_VALUE ? null : nv;
2601
2604
  }),
2605
+ clearQueue: () => {
2606
+ if (!queueEnabled)
2607
+ return;
2608
+ queue.set(signal([]));
2609
+ },
2602
2610
  // redeclare disabled with last value so that it is not affected by the resource's internal disablement logic
2603
2611
  disabled: computed(() => cb.isOpen() || lastValueRequest() === undefined),
2604
2612
  };