reactjrx 1.44.1 → 1.46.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.
Files changed (35) hide show
  1. package/README.md +1 -1
  2. package/dist/index.cjs +24 -20
  3. package/dist/index.d.ts +1 -0
  4. package/dist/index.js +24 -20
  5. package/dist/lib/binding/useObserve.test.d.ts +1 -0
  6. package/dist/lib/queries/client/cache/cache.garbage.test.d.ts +1 -0
  7. package/dist/lib/queries/client/cache/cacheClient.test.d.ts +1 -0
  8. package/dist/lib/queries/client/cache/logger.d.ts +2 -2
  9. package/dist/lib/queries/client/deduplication/deduplicate.test.d.ts +1 -0
  10. package/dist/lib/queries/client/invalidation/invalidation.test.d.ts +1 -0
  11. package/dist/lib/queries/client/invalidation/logger.d.ts +2 -2
  12. package/dist/lib/queries/client/keys/compareKeys.test.d.ts +1 -0
  13. package/dist/lib/queries/client/keys/keys.test.d.ts +1 -0
  14. package/dist/lib/queries/client/keys/serializeKey.test.d.ts +1 -0
  15. package/dist/lib/queries/client/keys/withKeyComparison.d.ts +16 -0
  16. package/dist/lib/queries/client/refetch/logger.d.ts +2 -2
  17. package/dist/lib/queries/client/refetch/refetch.test.d.ts +1 -0
  18. package/dist/lib/queries/react/useAsyncQuery.test.d.ts +1 -0
  19. package/dist/lib/queries/react/useQuery.deduplication.test.d.ts +1 -0
  20. package/dist/lib/queries/react/useQuery.invalidation.test.d.ts +1 -0
  21. package/dist/lib/queries/react/useQuery.keys.test.d.ts +1 -0
  22. package/dist/lib/queries/react/useQuery.test.d.ts +1 -0
  23. package/dist/lib/state/persistance/withPersistance.d.ts +2 -2
  24. package/dist/lib/state/signal.test.d.ts +1 -0
  25. package/dist/lib/utils/emitToSubject.d.ts +2 -0
  26. package/dist/lib/utils/shallowEqual.test.d.ts +1 -0
  27. package/dist/lib/utils/shareLatest.d.ts +10 -0
  28. package/dist/lib/utils/trackSubscriptions.d.ts +2 -0
  29. package/dist/lib/utils/useLiveRef.d.ts +1 -0
  30. package/dist/lib/utils/useLiveRef.test.d.ts +1 -0
  31. package/dist/lib/utils/useUnmountObservable.test.d.ts +1 -0
  32. package/dist/main.d.ts +1 -0
  33. package/dist/tests/testUtils.d.ts +1 -0
  34. package/dist/tests/utils.d.ts +1 -0
  35. package/package.json +10 -10
package/README.md CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  `reactjrx` is a javascript library which provides a simple and efficient API for handling global state, flow control, and queries in React applications using RxJS. With a small footprint and scalability to suit any project size, it is a great alternative to other popular libraries such as Recoil, Redux, React Query, Zustand, etc.
4
4
 
5
- Please visit the [documentation](https://bret-maxime.gitbook.io/reactjrx/) for more information on how to use.
5
+ Please visit the [documentation](https://bret-maxime.gitbook.io/reactjrx/) for more information on how to use.
package/dist/index.cjs CHANGED
@@ -145,6 +145,23 @@ function trigger(mapper = rxjs.identity) {
145
145
  }
146
146
  ];
147
147
  }
148
+ const useBehaviorSubject = (state) => {
149
+ const subject = useConstant(() => new rxjs.BehaviorSubject(state));
150
+ const completed = react.useRef(false);
151
+ react.useEffect(() => {
152
+ if (completed.current) {
153
+ subject.current = new rxjs.BehaviorSubject(state);
154
+ completed.current = false;
155
+ }
156
+ return () => {
157
+ if (!completed.current) {
158
+ subject.current.complete();
159
+ completed.current = true;
160
+ }
161
+ };
162
+ }, []);
163
+ return subject;
164
+ };
148
165
  const SIGNAL_RESET = Symbol("SIGNAL_RESET");
149
166
  function signal(options) {
150
167
  const { default: defaultValue2 } = options ?? {};
@@ -410,31 +427,14 @@ function retryBackoff(config) {
410
427
  );
411
428
  });
412
429
  }
413
- const useBehaviorSubject = (state) => {
414
- const subject = useConstant(() => new rxjs.BehaviorSubject(state));
415
- const completed = react.useRef(false);
416
- react.useEffect(() => {
417
- if (completed.current) {
418
- subject.current = new rxjs.BehaviorSubject(state);
419
- completed.current = false;
420
- }
421
- return () => {
422
- if (!completed.current) {
423
- subject.current.complete();
424
- completed.current = true;
425
- }
426
- };
427
- }, []);
428
- return subject;
429
- };
430
430
  function shallowEqual(objA, objB) {
431
- if (objA === null || objA === void 0 || objB === null || objB === void 0) {
431
+ if (objA === null || objA === void 0 || objB === void 0) {
432
432
  return objA === objB;
433
433
  }
434
434
  if (typeof objA !== "object" || typeof objB !== "object") {
435
435
  return objA === objB;
436
436
  }
437
- if (objA.constructor !== objB.constructor) {
437
+ if (objA.constructor !== (objB == null ? void 0 : objB.constructor)) {
438
438
  return false;
439
439
  }
440
440
  const keysA = Object.keys(objA);
@@ -818,7 +818,10 @@ const resetStyle = { backgroundColor: "transparent", color: "inherit" };
818
818
  function createLogger(env) {
819
819
  const _logger = {
820
820
  namespaces: [
821
- { name: "@reactjrx", style: { backgroundColor: "#d02f4e", color: "white" } }
821
+ {
822
+ name: "@reactjrx",
823
+ style: { backgroundColor: "#d02f4e", color: "white" }
824
+ }
822
825
  ],
823
826
  namespace(name, style) {
824
827
  const logger2 = createLogger(env);
@@ -1712,6 +1715,7 @@ exports.retryBackoff = retryBackoff;
1712
1715
  exports.signal = signal;
1713
1716
  exports.trigger = trigger;
1714
1717
  exports.useAsyncQuery = useAsyncQuery;
1718
+ exports.useBehaviorSubject = useBehaviorSubject;
1715
1719
  exports.useLiveRef = useLiveRef;
1716
1720
  exports.useObserve = useObserve;
1717
1721
  exports.useObserveCallback = useObserveCallback;
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export * from "./lib/binding/useSubscribe";
3
3
  export * from "./lib/binding/useObserveCallback";
4
4
  export * from "./lib/binding/trigger";
5
5
  export * from "./lib/binding/useSubject";
6
+ export * from "./lib/binding/useBehaviorSubject";
6
7
  export * from "./lib/state/signal";
7
8
  export * from "./lib/state/useSignal";
8
9
  export * from "./lib/state/useSetSignal";
package/dist/index.js CHANGED
@@ -143,6 +143,23 @@ function trigger(mapper = identity) {
143
143
  }
144
144
  ];
145
145
  }
146
+ const useBehaviorSubject = (state) => {
147
+ const subject = useConstant(() => new BehaviorSubject(state));
148
+ const completed = useRef(false);
149
+ useEffect(() => {
150
+ if (completed.current) {
151
+ subject.current = new BehaviorSubject(state);
152
+ completed.current = false;
153
+ }
154
+ return () => {
155
+ if (!completed.current) {
156
+ subject.current.complete();
157
+ completed.current = true;
158
+ }
159
+ };
160
+ }, []);
161
+ return subject;
162
+ };
146
163
  const SIGNAL_RESET = Symbol("SIGNAL_RESET");
147
164
  function signal(options) {
148
165
  const { default: defaultValue2 } = options ?? {};
@@ -408,31 +425,14 @@ function retryBackoff(config) {
408
425
  );
409
426
  });
410
427
  }
411
- const useBehaviorSubject = (state) => {
412
- const subject = useConstant(() => new BehaviorSubject(state));
413
- const completed = useRef(false);
414
- useEffect(() => {
415
- if (completed.current) {
416
- subject.current = new BehaviorSubject(state);
417
- completed.current = false;
418
- }
419
- return () => {
420
- if (!completed.current) {
421
- subject.current.complete();
422
- completed.current = true;
423
- }
424
- };
425
- }, []);
426
- return subject;
427
- };
428
428
  function shallowEqual(objA, objB) {
429
- if (objA === null || objA === void 0 || objB === null || objB === void 0) {
429
+ if (objA === null || objA === void 0 || objB === void 0) {
430
430
  return objA === objB;
431
431
  }
432
432
  if (typeof objA !== "object" || typeof objB !== "object") {
433
433
  return objA === objB;
434
434
  }
435
- if (objA.constructor !== objB.constructor) {
435
+ if (objA.constructor !== (objB == null ? void 0 : objB.constructor)) {
436
436
  return false;
437
437
  }
438
438
  const keysA = Object.keys(objA);
@@ -816,7 +816,10 @@ const resetStyle = { backgroundColor: "transparent", color: "inherit" };
816
816
  function createLogger(env) {
817
817
  const _logger = {
818
818
  namespaces: [
819
- { name: "@reactjrx", style: { backgroundColor: "#d02f4e", color: "white" } }
819
+ {
820
+ name: "@reactjrx",
821
+ style: { backgroundColor: "#d02f4e", color: "white" }
822
+ }
820
823
  ],
821
824
  namespace(name, style) {
822
825
  const logger2 = createLogger(env);
@@ -1711,6 +1714,7 @@ export {
1711
1714
  signal,
1712
1715
  trigger,
1713
1716
  useAsyncQuery,
1717
+ useBehaviorSubject,
1714
1718
  useLiveRef,
1715
1719
  useObserve,
1716
1720
  useObserveCallback,
@@ -0,0 +1 @@
1
+ export {};
@@ -14,8 +14,8 @@ export declare const logger: {
14
14
  namespaces: string;
15
15
  styles: string[];
16
16
  };
17
- print(method: "log" | "warn" | "error" | "group", ...message: any[]): any;
18
- printWithoutNamespace(method: "log" | "warn" | "error" | "group", ...message: any[]): any;
17
+ print(method: "error" | "log" | "warn" | "group", ...message: any[]): any;
18
+ printWithoutNamespace(method: "error" | "log" | "warn" | "group", ...message: any[]): any;
19
19
  log(...message: any): any;
20
20
  warn(...message: any): any;
21
21
  error(...message: any): any;
@@ -14,8 +14,8 @@ export declare const logger: {
14
14
  namespaces: string;
15
15
  styles: string[];
16
16
  };
17
- print(method: "log" | "warn" | "error" | "group", ...message: any[]): any;
18
- printWithoutNamespace(method: "log" | "warn" | "error" | "group", ...message: any[]): any;
17
+ print(method: "error" | "log" | "warn" | "group", ...message: any[]): any;
18
+ printWithoutNamespace(method: "error" | "log" | "warn" | "group", ...message: any[]): any;
19
19
  log(...message: any): any;
20
20
  warn(...message: any): any;
21
21
  error(...message: any): any;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -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)>;
@@ -14,8 +14,8 @@ export declare const logger: {
14
14
  namespaces: string;
15
15
  styles: string[];
16
16
  };
17
- print(method: "log" | "warn" | "error" | "group", ...message: any[]): any;
18
- printWithoutNamespace(method: "log" | "warn" | "error" | "group", ...message: any[]): any;
17
+ print(method: "error" | "log" | "warn" | "group", ...message: any[]): any;
18
+ printWithoutNamespace(method: "error" | "log" | "warn" | "group", ...message: any[]): any;
19
19
  log(...message: any): any;
20
20
  warn(...message: any): any;
21
21
  error(...message: any): any;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -7,8 +7,8 @@ export interface WithPersistanceReturn<T> {
7
7
  persistValue: (params: {
8
8
  adapter: Adapter;
9
9
  }) => Promise<void>;
10
- setValue: Signal<T, T>['setState'];
11
- $: Signal<T, T>['subject'];
10
+ setValue: Signal<T, T>["setState"];
11
+ $: Signal<T, T>["subject"];
12
12
  options: {
13
13
  key?: string;
14
14
  };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { type MonoTypeOperatorFunction, type Subject } from "rxjs";
2
+ export declare function emitToSubject<T>(subject: Subject<T>): MonoTypeOperatorFunction<T>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import { type MonoTypeOperatorFunction } from "rxjs";
2
+ /**
3
+ * Share the latest value to every new observers but clean up
4
+ * otherwise.
5
+ *
6
+ * We cannot use shareReplay with react since it would never clean
7
+ * selectors and create memory leak. shareLatest ensure when the selector
8
+ * is not mounted anywhere we reset it
9
+ */
10
+ export declare const shareLatest: <T>() => MonoTypeOperatorFunction<T>;
@@ -0,0 +1,2 @@
1
+ import { type Observable } from "rxjs";
2
+ export declare function trackSubscriptions(onCountUpdate: (activeSubscriptions: number) => void): <T>(source$: Observable<T>) => Observable<T>;
@@ -1 +1,2 @@
1
+ /// <reference types="react" />
1
2
  export declare const useLiveRef: <T>(value: T) => import("react").MutableRefObject<T>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/dist/main.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare const printQuery: (data: any) => string;
@@ -0,0 +1 @@
1
+ export declare const waitForTimeout: (timeout: number) => Promise<unknown>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "reactjrx",
3
3
  "private": false,
4
- "version": "1.44.1",
4
+ "version": "1.46.0",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"
@@ -39,25 +39,25 @@
39
39
  "devDependencies": {
40
40
  "@types/react": "^18.0.28",
41
41
  "@types/react-dom": "^18.0.11",
42
- "@typescript-eslint/eslint-plugin": "^5.59.0",
42
+ "@typescript-eslint/eslint-plugin": "^6.11.0",
43
43
  "@vitejs/plugin-react": "^4.0.0",
44
44
  "eslint": "^8.47.0",
45
- "eslint-config-prettier": "^8.8.0",
46
- "eslint-config-standard-with-typescript": "^34.0.1",
45
+ "eslint-config-prettier": "^9.0.0",
46
+ "eslint-config-standard-with-typescript": "^39.1.1",
47
47
  "eslint-plugin-import": "^2.27.5",
48
- "eslint-plugin-n": "^15.7.0",
48
+ "eslint-plugin-n": "^16.3.1",
49
49
  "eslint-plugin-promise": "^6.1.1",
50
50
  "eslint-plugin-react": "^7.32.2",
51
51
  "global-jsdom": "^9.0.1",
52
52
  "jsdom": "^22.0.0",
53
- "prettier": "^2.8.7",
54
- "rollup-plugin-node-externals": "^5.1.2",
53
+ "prettier": "^3.1.0",
54
+ "rollup-plugin-node-externals": "^6.1.2",
55
55
  "rxjs": "^7.8.0",
56
- "semantic-release": "^21.0.1",
56
+ "semantic-release": "^22.0.7",
57
57
  "typescript": "^5.0.4",
58
58
  "vite": "^4.2.1",
59
- "vite-plugin-dts": "^2.2.0",
60
- "vitest": "^0.31.0",
59
+ "vite-plugin-dts": "^3.6.3",
60
+ "vitest": "^0.34.6",
61
61
  "@testing-library/react": "^14.0.0",
62
62
  "@types/node": "^18.15.11"
63
63
  },