reactjrx 1.59.0 → 1.60.0
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/dist/index.cjs +27 -25
- package/dist/index.js +27 -25
- package/dist/lib/queries/client/mutations/MutationClient.d.ts +5 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1621,6 +1621,10 @@ class MutationClient {
|
|
|
1621
1621
|
__publicField(this, "mutationResults$", new rxjs.BehaviorSubject(/* @__PURE__ */ new Map()));
|
|
1622
1622
|
__publicField(this, "mutate$", new rxjs.Subject());
|
|
1623
1623
|
__publicField(this, "reset$", new rxjs.Subject());
|
|
1624
|
+
/**
|
|
1625
|
+
* Observable to track how many running mutations per runner
|
|
1626
|
+
*/
|
|
1627
|
+
__publicField(this, "isMutatingSubject", new rxjs.BehaviorSubject([]));
|
|
1624
1628
|
this.mutate$.pipe(
|
|
1625
1629
|
rxjs.tap(({ options, args }) => {
|
|
1626
1630
|
const { mutationKey } = options;
|
|
@@ -1666,6 +1670,21 @@ class MutationClient {
|
|
|
1666
1670
|
(_a = this.mutationRunnersByKey$.getValue().get(serializedKey)) == null ? void 0 : _a.reset$.next();
|
|
1667
1671
|
})
|
|
1668
1672
|
).subscribe();
|
|
1673
|
+
this.mutationRunnersByKey$.pipe(
|
|
1674
|
+
rxjs.switchMap((mapItem) => {
|
|
1675
|
+
const mutationRunners = Array.from(mapItem.entries()).map(
|
|
1676
|
+
([, value]) => value.mutationsRunning$.pipe(
|
|
1677
|
+
rxjs.map((number) => [value.mutationKey, number])
|
|
1678
|
+
)
|
|
1679
|
+
);
|
|
1680
|
+
const mutationRunnersMutationsRunning$ = rxjs.combineLatest([
|
|
1681
|
+
// when map is empty we still need to push 0
|
|
1682
|
+
rxjs.of([[], 0]),
|
|
1683
|
+
...mutationRunners
|
|
1684
|
+
]);
|
|
1685
|
+
return mutationRunnersMutationsRunning$;
|
|
1686
|
+
})
|
|
1687
|
+
).subscribe(this.isMutatingSubject);
|
|
1669
1688
|
}
|
|
1670
1689
|
/**
|
|
1671
1690
|
* @helper
|
|
@@ -1689,36 +1708,18 @@ class MutationClient {
|
|
|
1689
1708
|
getMutationRunnersByKey(key) {
|
|
1690
1709
|
return this.mutationRunnersByKey$.getValue().get(key);
|
|
1691
1710
|
}
|
|
1692
|
-
|
|
1693
|
-
* @returns number of mutation runnings
|
|
1694
|
-
*/
|
|
1695
|
-
runningMutations({ mutationKey, predicate } = {}) {
|
|
1711
|
+
useIsMutating({ mutationKey, predicate } = {}) {
|
|
1696
1712
|
const defaultPredicate = ({ options }) => mutationKey ? (
|
|
1697
1713
|
// @todo optimize
|
|
1698
1714
|
serializeKey(options.mutationKey) === serializeKey(mutationKey)
|
|
1699
1715
|
) : true;
|
|
1700
1716
|
const finalPredicate = predicate ?? defaultPredicate;
|
|
1701
|
-
const
|
|
1702
|
-
|
|
1703
|
-
);
|
|
1704
|
-
const lastValue =
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
const value$ = this.mutationRunnersByKey$.pipe(
|
|
1708
|
-
rxjs.switchMap((map2) => {
|
|
1709
|
-
const mutationRunners = Array.from(map2.entries()).filter(
|
|
1710
|
-
([, value]) => finalPredicate({ options: { mutationKey: value.mutationKey } })
|
|
1711
|
-
).map(([, value]) => value);
|
|
1712
|
-
const mutationRunnersMutationsRunning$ = rxjs.combineLatest([
|
|
1713
|
-
// when map is empty we still need to push 0
|
|
1714
|
-
rxjs.of(0),
|
|
1715
|
-
...mutationRunners.map(
|
|
1716
|
-
(mutationRunner) => mutationRunner.mutationsRunning$
|
|
1717
|
-
)
|
|
1718
|
-
]);
|
|
1719
|
-
return mutationRunnersMutationsRunning$;
|
|
1720
|
-
}),
|
|
1721
|
-
rxjs.map((values) => values.reduce((acc, value) => value + acc, 0)),
|
|
1717
|
+
const reduceByNumber = (entries) => entries.reduce((acc, [mutationKey2, value]) => {
|
|
1718
|
+
return finalPredicate({ options: { mutationKey: mutationKey2 } }) ? value + acc : acc;
|
|
1719
|
+
}, 0);
|
|
1720
|
+
const lastValue = reduceByNumber(this.isMutatingSubject.getValue());
|
|
1721
|
+
const value$ = this.isMutatingSubject.pipe(
|
|
1722
|
+
rxjs.map((mutationRunningByKeys) => reduceByNumber(mutationRunningByKeys)),
|
|
1722
1723
|
rxjs.distinctUntilChanged()
|
|
1723
1724
|
);
|
|
1724
1725
|
return { value$, lastValue };
|
|
@@ -1772,6 +1773,7 @@ class MutationClient {
|
|
|
1772
1773
|
this.mutate$.complete();
|
|
1773
1774
|
this.mutationResults$.complete();
|
|
1774
1775
|
this.mutationRunnersByKey$.complete();
|
|
1776
|
+
this.isMutatingSubject.complete();
|
|
1775
1777
|
}
|
|
1776
1778
|
}
|
|
1777
1779
|
const createClient = () => {
|
package/dist/index.js
CHANGED
|
@@ -1619,6 +1619,10 @@ class MutationClient {
|
|
|
1619
1619
|
__publicField(this, "mutationResults$", new BehaviorSubject(/* @__PURE__ */ new Map()));
|
|
1620
1620
|
__publicField(this, "mutate$", new Subject());
|
|
1621
1621
|
__publicField(this, "reset$", new Subject());
|
|
1622
|
+
/**
|
|
1623
|
+
* Observable to track how many running mutations per runner
|
|
1624
|
+
*/
|
|
1625
|
+
__publicField(this, "isMutatingSubject", new BehaviorSubject([]));
|
|
1622
1626
|
this.mutate$.pipe(
|
|
1623
1627
|
tap(({ options, args }) => {
|
|
1624
1628
|
const { mutationKey } = options;
|
|
@@ -1664,6 +1668,21 @@ class MutationClient {
|
|
|
1664
1668
|
(_a = this.mutationRunnersByKey$.getValue().get(serializedKey)) == null ? void 0 : _a.reset$.next();
|
|
1665
1669
|
})
|
|
1666
1670
|
).subscribe();
|
|
1671
|
+
this.mutationRunnersByKey$.pipe(
|
|
1672
|
+
switchMap((mapItem) => {
|
|
1673
|
+
const mutationRunners = Array.from(mapItem.entries()).map(
|
|
1674
|
+
([, value]) => value.mutationsRunning$.pipe(
|
|
1675
|
+
map((number) => [value.mutationKey, number])
|
|
1676
|
+
)
|
|
1677
|
+
);
|
|
1678
|
+
const mutationRunnersMutationsRunning$ = combineLatest([
|
|
1679
|
+
// when map is empty we still need to push 0
|
|
1680
|
+
of([[], 0]),
|
|
1681
|
+
...mutationRunners
|
|
1682
|
+
]);
|
|
1683
|
+
return mutationRunnersMutationsRunning$;
|
|
1684
|
+
})
|
|
1685
|
+
).subscribe(this.isMutatingSubject);
|
|
1667
1686
|
}
|
|
1668
1687
|
/**
|
|
1669
1688
|
* @helper
|
|
@@ -1687,36 +1706,18 @@ class MutationClient {
|
|
|
1687
1706
|
getMutationRunnersByKey(key) {
|
|
1688
1707
|
return this.mutationRunnersByKey$.getValue().get(key);
|
|
1689
1708
|
}
|
|
1690
|
-
|
|
1691
|
-
* @returns number of mutation runnings
|
|
1692
|
-
*/
|
|
1693
|
-
runningMutations({ mutationKey, predicate } = {}) {
|
|
1709
|
+
useIsMutating({ mutationKey, predicate } = {}) {
|
|
1694
1710
|
const defaultPredicate = ({ options }) => mutationKey ? (
|
|
1695
1711
|
// @todo optimize
|
|
1696
1712
|
serializeKey(options.mutationKey) === serializeKey(mutationKey)
|
|
1697
1713
|
) : true;
|
|
1698
1714
|
const finalPredicate = predicate ?? defaultPredicate;
|
|
1699
|
-
const
|
|
1700
|
-
|
|
1701
|
-
);
|
|
1702
|
-
const lastValue =
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
const value$ = this.mutationRunnersByKey$.pipe(
|
|
1706
|
-
switchMap((map2) => {
|
|
1707
|
-
const mutationRunners = Array.from(map2.entries()).filter(
|
|
1708
|
-
([, value]) => finalPredicate({ options: { mutationKey: value.mutationKey } })
|
|
1709
|
-
).map(([, value]) => value);
|
|
1710
|
-
const mutationRunnersMutationsRunning$ = combineLatest([
|
|
1711
|
-
// when map is empty we still need to push 0
|
|
1712
|
-
of(0),
|
|
1713
|
-
...mutationRunners.map(
|
|
1714
|
-
(mutationRunner) => mutationRunner.mutationsRunning$
|
|
1715
|
-
)
|
|
1716
|
-
]);
|
|
1717
|
-
return mutationRunnersMutationsRunning$;
|
|
1718
|
-
}),
|
|
1719
|
-
map((values) => values.reduce((acc, value) => value + acc, 0)),
|
|
1715
|
+
const reduceByNumber = (entries) => entries.reduce((acc, [mutationKey2, value]) => {
|
|
1716
|
+
return finalPredicate({ options: { mutationKey: mutationKey2 } }) ? value + acc : acc;
|
|
1717
|
+
}, 0);
|
|
1718
|
+
const lastValue = reduceByNumber(this.isMutatingSubject.getValue());
|
|
1719
|
+
const value$ = this.isMutatingSubject.pipe(
|
|
1720
|
+
map((mutationRunningByKeys) => reduceByNumber(mutationRunningByKeys)),
|
|
1720
1721
|
distinctUntilChanged()
|
|
1721
1722
|
);
|
|
1722
1723
|
return { value$, lastValue };
|
|
@@ -1770,6 +1771,7 @@ class MutationClient {
|
|
|
1770
1771
|
this.mutate$.complete();
|
|
1771
1772
|
this.mutationResults$.complete();
|
|
1772
1773
|
this.mutationRunnersByKey$.complete();
|
|
1774
|
+
this.isMutatingSubject.complete();
|
|
1773
1775
|
}
|
|
1774
1776
|
}
|
|
1775
1777
|
const createClient = () => {
|
|
@@ -37,6 +37,10 @@ export declare class MutationClient {
|
|
|
37
37
|
reset$: Subject<{
|
|
38
38
|
key: QueryKey;
|
|
39
39
|
}>;
|
|
40
|
+
/**
|
|
41
|
+
* Observable to track how many running mutations per runner
|
|
42
|
+
*/
|
|
43
|
+
isMutatingSubject: BehaviorSubject<(readonly [MutationKey, number])[]>;
|
|
40
44
|
constructor();
|
|
41
45
|
/**
|
|
42
46
|
* @helper
|
|
@@ -62,10 +66,7 @@ export declare class MutationClient {
|
|
|
62
66
|
} & {
|
|
63
67
|
mutationKey: MutationKey;
|
|
64
68
|
}) | undefined;
|
|
65
|
-
|
|
66
|
-
* @returns number of mutation runnings
|
|
67
|
-
*/
|
|
68
|
-
runningMutations({ mutationKey, predicate }?: MutationFilters): {
|
|
69
|
+
useIsMutating({ mutationKey, predicate }?: MutationFilters): {
|
|
69
70
|
value$: Observable<number>;
|
|
70
71
|
lastValue: number;
|
|
71
72
|
};
|