@mmstack/resource 20.8.4 → 20.8.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.
- package/fesm2022/mmstack-resource.mjs +17 -6
- package/fesm2022/mmstack-resource.mjs.map +1 -1
- package/index.d.ts +22 -3
- package/package.json +1 -1
|
@@ -2504,13 +2504,20 @@ function mutationResource(request, options0 = {}) {
|
|
|
2504
2504
|
return eq(a, b);
|
|
2505
2505
|
},
|
|
2506
2506
|
}]));
|
|
2507
|
-
const
|
|
2507
|
+
const queueEnabled = !!options.queue;
|
|
2508
|
+
const queueKeyFn = typeof options.queue === 'object' ? options.queue.key : undefined;
|
|
2509
|
+
const queue = linkedSignal(...(ngDevMode ? [{ debugName: "queue", source: () => queueKeyFn?.(),
|
|
2510
|
+
computation: () => signal([]) }] : [{
|
|
2511
|
+
source: () => queueKeyFn?.(),
|
|
2512
|
+
computation: () => signal([]),
|
|
2513
|
+
}]));
|
|
2508
2514
|
let ctx = undefined;
|
|
2509
2515
|
const queueRef = effect(() => {
|
|
2510
|
-
const
|
|
2516
|
+
const q = queue(); // subscribe to swaps (key change / clearQueue)
|
|
2517
|
+
const nextInQueue = q().at(0); // subscribe to contents
|
|
2511
2518
|
if (nextInQueue === undefined || next() !== NULL_VALUE)
|
|
2512
2519
|
return;
|
|
2513
|
-
|
|
2520
|
+
q.update((arr) => arr.slice(1));
|
|
2514
2521
|
const [value, ictx] = nextInQueue;
|
|
2515
2522
|
try {
|
|
2516
2523
|
ctx = onMutate?.(value, ictx);
|
|
@@ -2635,7 +2642,6 @@ function mutationResource(request, options0 = {}) {
|
|
|
2635
2642
|
ctx = undefined;
|
|
2636
2643
|
next.set(NULL_VALUE);
|
|
2637
2644
|
});
|
|
2638
|
-
const shouldQueue = options.queue ?? false;
|
|
2639
2645
|
const ref = {
|
|
2640
2646
|
...resource,
|
|
2641
2647
|
destroy: () => {
|
|
@@ -2645,8 +2651,8 @@ function mutationResource(request, options0 = {}) {
|
|
|
2645
2651
|
resource.destroy();
|
|
2646
2652
|
},
|
|
2647
2653
|
mutate: (value, ictx) => {
|
|
2648
|
-
if (
|
|
2649
|
-
return queue.update((
|
|
2654
|
+
if (queueEnabled) {
|
|
2655
|
+
return queue().update((arr) => [...arr, [value, ictx]]);
|
|
2650
2656
|
}
|
|
2651
2657
|
else {
|
|
2652
2658
|
// latest-wins: a mutation already in flight gets superseded (its request is
|
|
@@ -2680,6 +2686,11 @@ function mutationResource(request, options0 = {}) {
|
|
|
2680
2686
|
const nv = next();
|
|
2681
2687
|
return nv === NULL_VALUE ? null : nv;
|
|
2682
2688
|
}),
|
|
2689
|
+
clearQueue: () => {
|
|
2690
|
+
if (!queueEnabled)
|
|
2691
|
+
return;
|
|
2692
|
+
queue.set(signal([]));
|
|
2693
|
+
},
|
|
2683
2694
|
// redeclare disabled with last value so that it is not affected by the resource's internal disablement logic
|
|
2684
2695
|
disabled: computed(() => cb.isOpen() || lastValueRequest() === undefined),
|
|
2685
2696
|
};
|