@mmstack/resource 22.1.4 → 22.1.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.
|
@@ -2471,14 +2471,17 @@ function mutationResource(request, options0 = {}) {
|
|
|
2471
2471
|
return false;
|
|
2472
2472
|
return eq(a, b);
|
|
2473
2473
|
} });
|
|
2474
|
-
const
|
|
2475
|
-
|
|
2474
|
+
const queueEnabled = !!options.queue;
|
|
2475
|
+
const queueKeyFn = typeof options.queue === 'object' ? options.queue.key : undefined;
|
|
2476
|
+
const queue = linkedSignal({ ...(ngDevMode ? { debugName: "queue" } : /* istanbul ignore next */ {}), source: () => queueKeyFn?.(),
|
|
2477
|
+
computation: () => signal([]) });
|
|
2476
2478
|
let ctx = undefined;
|
|
2477
2479
|
const queueRef = effect(() => {
|
|
2478
|
-
const
|
|
2480
|
+
const q = queue(); // subscribe to swaps (key change / clearQueue)
|
|
2481
|
+
const nextInQueue = q().at(0); // subscribe to contents
|
|
2479
2482
|
if (nextInQueue === undefined || next() !== NULL_VALUE)
|
|
2480
2483
|
return;
|
|
2481
|
-
|
|
2484
|
+
q.update((arr) => arr.slice(1));
|
|
2482
2485
|
const [value, ictx] = nextInQueue;
|
|
2483
2486
|
try {
|
|
2484
2487
|
ctx = onMutate?.(value, ictx);
|
|
@@ -2578,7 +2581,6 @@ function mutationResource(request, options0 = {}) {
|
|
|
2578
2581
|
ctx = undefined;
|
|
2579
2582
|
next.set(NULL_VALUE);
|
|
2580
2583
|
});
|
|
2581
|
-
const shouldQueue = options.queue ?? false;
|
|
2582
2584
|
const ref = {
|
|
2583
2585
|
...resource,
|
|
2584
2586
|
destroy: () => {
|
|
@@ -2588,8 +2590,8 @@ function mutationResource(request, options0 = {}) {
|
|
|
2588
2590
|
resource.destroy();
|
|
2589
2591
|
},
|
|
2590
2592
|
mutate: (value, ictx) => {
|
|
2591
|
-
if (
|
|
2592
|
-
return queue.update((
|
|
2593
|
+
if (queueEnabled) {
|
|
2594
|
+
return queue().update((arr) => [...arr, [value, ictx]]);
|
|
2593
2595
|
}
|
|
2594
2596
|
else {
|
|
2595
2597
|
// latest-wins: a mutation already in flight gets superseded (its request is
|
|
@@ -2623,6 +2625,11 @@ function mutationResource(request, options0 = {}) {
|
|
|
2623
2625
|
const nv = next();
|
|
2624
2626
|
return nv === NULL_VALUE ? null : nv;
|
|
2625
2627
|
}),
|
|
2628
|
+
clearQueue: () => {
|
|
2629
|
+
if (!queueEnabled)
|
|
2630
|
+
return;
|
|
2631
|
+
queue.set(signal([]));
|
|
2632
|
+
},
|
|
2626
2633
|
// redeclare disabled with last value so that it is not affected by the resource's internal disablement logic
|
|
2627
2634
|
disabled: computed(() => cb.isOpen() || lastValueRequest() === undefined),
|
|
2628
2635
|
};
|