reactjrx 1.32.0 → 1.33.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 CHANGED
@@ -684,6 +684,33 @@ const autoRefetch = (options = {}) => (source) => {
684
684
  })
685
685
  );
686
686
  };
687
+ function isDefined(arg) {
688
+ return arg !== null && arg !== void 0;
689
+ }
690
+ const withKeyComparison = (stream) => stream.pipe(
691
+ rxjs.startWith(void 0),
692
+ rxjs.pairwise(),
693
+ rxjs.map(([previous, current]) => {
694
+ if (current) {
695
+ if (!previous) {
696
+ return {
697
+ ...current,
698
+ previousKey: void 0,
699
+ isUsingDifferentKey: true
700
+ };
701
+ }
702
+ const serializedKey = serializeKey(current.key);
703
+ const serializedPreviousKey = serializeKey(previous.key);
704
+ return {
705
+ ...current,
706
+ previousKey: (previous == null ? void 0 : previous.key) ?? current.key,
707
+ isUsingDifferentKey: serializedPreviousKey !== serializedKey
708
+ };
709
+ }
710
+ return void 0;
711
+ }),
712
+ rxjs.filter(isDefined)
713
+ );
687
714
  function useQuery(keyOrQuery, queryOrOptionOrNothing, optionsOrNothing) {
688
715
  const query = Array.isArray(keyOrQuery) ? queryOrOptionOrNothing : keyOrQuery;
689
716
  const options = optionsOrNothing ?? (queryOrOptionOrNothing !== query ? queryOrOptionOrNothing : void 0) ?? {};
@@ -747,13 +774,15 @@ function useQuery(keyOrQuery, queryOrOptionOrNothing, optionsOrNothing) {
747
774
  options: options2,
748
775
  query: query2
749
776
  })),
777
+ withKeyComparison,
750
778
  rxjs.filter(({ enabled }) => enabled),
751
- rxjs.switchMap(({ key: key2, options: options2, query: query2 }) => {
779
+ rxjs.switchMap(({ key: key2, options: options2, isUsingDifferentKey, query: query2 }) => {
752
780
  const serializedKey = serializeKey(key2);
753
781
  return rxjs.of(null).pipe(
754
782
  rxjs.tap(() => {
755
783
  data$.current.next({
756
784
  ...data$.current.getValue(),
785
+ data: isUsingDifferentKey ? void 0 : data$.current.getValue().data,
757
786
  error: void 0,
758
787
  isLoading: true
759
788
  });
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { useRef, useMemo, useCallback, useSyncExternalStore, useEffect, createContext, memo, useContext, useState } from "react";
2
- import { distinctUntilChanged, tap, finalize, catchError, EMPTY, Subject, identity, BehaviorSubject, of, zip, from, map, merge, throttleTime, switchMap, defer, iif, timer, throwError, take, startWith, combineLatest, first, takeUntil, filter, concatMap as concatMap$1, mergeMap, skip, interval, withLatestFrom, shareReplay, repeat, share, retry } from "rxjs";
2
+ import { distinctUntilChanged, tap, finalize, catchError, EMPTY, Subject, identity, BehaviorSubject, of, zip, from, map, merge, throttleTime, switchMap, defer, iif, timer, throwError, take, startWith, combineLatest, first, takeUntil, filter, concatMap as concatMap$1, mergeMap, skip, interval, withLatestFrom, shareReplay, repeat, pairwise, share, retry } from "rxjs";
3
3
  import { jsx } from "react/jsx-runtime";
4
4
  import { retryWhen, concatMap, tap as tap$1 } from "rxjs/operators";
5
5
  const useLiveRef = (value) => {
@@ -682,6 +682,33 @@ const autoRefetch = (options = {}) => (source) => {
682
682
  })
683
683
  );
684
684
  };
685
+ function isDefined(arg) {
686
+ return arg !== null && arg !== void 0;
687
+ }
688
+ const withKeyComparison = (stream) => stream.pipe(
689
+ startWith(void 0),
690
+ pairwise(),
691
+ map(([previous, current]) => {
692
+ if (current) {
693
+ if (!previous) {
694
+ return {
695
+ ...current,
696
+ previousKey: void 0,
697
+ isUsingDifferentKey: true
698
+ };
699
+ }
700
+ const serializedKey = serializeKey(current.key);
701
+ const serializedPreviousKey = serializeKey(previous.key);
702
+ return {
703
+ ...current,
704
+ previousKey: (previous == null ? void 0 : previous.key) ?? current.key,
705
+ isUsingDifferentKey: serializedPreviousKey !== serializedKey
706
+ };
707
+ }
708
+ return void 0;
709
+ }),
710
+ filter(isDefined)
711
+ );
685
712
  function useQuery(keyOrQuery, queryOrOptionOrNothing, optionsOrNothing) {
686
713
  const query = Array.isArray(keyOrQuery) ? queryOrOptionOrNothing : keyOrQuery;
687
714
  const options = optionsOrNothing ?? (queryOrOptionOrNothing !== query ? queryOrOptionOrNothing : void 0) ?? {};
@@ -745,13 +772,15 @@ function useQuery(keyOrQuery, queryOrOptionOrNothing, optionsOrNothing) {
745
772
  options: options2,
746
773
  query: query2
747
774
  })),
775
+ withKeyComparison,
748
776
  filter(({ enabled }) => enabled),
749
- switchMap(({ key: key2, options: options2, query: query2 }) => {
777
+ switchMap(({ key: key2, options: options2, isUsingDifferentKey, query: query2 }) => {
750
778
  const serializedKey = serializeKey(key2);
751
779
  return of(null).pipe(
752
780
  tap(() => {
753
781
  data$.current.next({
754
782
  ...data$.current.getValue(),
783
+ data: isUsingDifferentKey ? void 0 : data$.current.getValue().data,
755
784
  error: void 0,
756
785
  isLoading: true
757
786
  });
@@ -0,0 +1,16 @@
1
+ import type { Observable } from "rxjs";
2
+ export declare const withKeyComparison: <T extends {
3
+ key: any[];
4
+ }>(stream: Observable<T>) => Observable<(T & {
5
+ previousKey: undefined;
6
+ isUsingDifferentKey: boolean;
7
+ } extends infer T_1 ? T_1 extends T & {
8
+ previousKey: undefined;
9
+ isUsingDifferentKey: boolean;
10
+ } ? T_1 extends null | undefined ? never : T_1 : never : never) | (T & {
11
+ previousKey: any[];
12
+ isUsingDifferentKey: boolean;
13
+ } extends infer T_2 ? T_2 extends T & {
14
+ previousKey: any[];
15
+ isUsingDifferentKey: boolean;
16
+ } ? T_2 extends null | undefined ? never : T_2 : never : never)>;
@@ -0,0 +1 @@
1
+ export declare function isDefined<T>(arg: T | null | undefined): arg is T extends null | undefined ? never : T;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "reactjrx",
3
3
  "private": false,
4
- "version": "1.32.0",
4
+ "version": "1.33.0",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"