reactjrx 1.99.0 → 1.101.1

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.
@@ -3,6 +3,7 @@ import { Observable, BehaviorSubject } from 'rxjs';
3
3
  interface Option<R = undefined> {
4
4
  defaultValue: R;
5
5
  unsubscribeOnUnmount?: boolean;
6
+ compareFn?: (a: R, b: R) => boolean;
6
7
  }
7
8
  export declare function useObserve<T>(source: BehaviorSubject<T>): T;
8
9
  export declare function useObserve<T>(source: Observable<T>): T | undefined;
@@ -1,6 +1,20 @@
1
1
  import { Observable } from 'rxjs';
2
- export declare function makeObservable<Data>(fn: () => Observable<Data> | Data | Promise<Data>): Observable<Data>;
3
- export declare function makeObservable<Data>(fn: () => Data): Data extends Observable<infer ObservedData> ? Observable<ObservedData> : Data extends Promise<infer ThenData> ? Observable<ThenData> : Observable<Data>;
4
- export declare function makeObservable<Data>(fn: Data): Observable<Data>;
5
- export declare function makeObservable<Data>(fn: Promise<Data>): Observable<Data>;
2
+ type FnReturnToObservable<T> = T extends Observable<infer ObservedData> ? ObservedData : T extends Promise<infer ThenData> ? ThenData : T;
6
3
  export declare function makeObservable<Data>(fn: Observable<Data>): Observable<Data>;
4
+ export declare function makeObservable<Data>(fn: Promise<Data>): Observable<Data>;
5
+ export declare function makeObservable<Data>(fn: Promise<Data> | Observable<Data>): Observable<Data>;
6
+ export declare function makeObservable<Data>(fn: () => Promise<Data> | Observable<Data>): Observable<Data>;
7
+ /**
8
+ * Generic factory
9
+ */
10
+ export declare function makeObservable<TContext>(fn: () => Promise<TContext | undefined> | Observable<TContext | undefined> | TContext | undefined): Observable<undefined | TContext>;
11
+ /**
12
+ * Generic factory
13
+ */
14
+ export declare function makeObservable<Return>(fn: () => Return): Observable<FnReturnToObservable<Return>>;
15
+ /**
16
+ * Generic factory OR Observable
17
+ */
18
+ export declare function makeObservable<Data, Return>(fn: Observable<Data> | (() => Return)): Observable<Data | FnReturnToObservable<Return>>;
19
+ export declare function makeObservable<Data>(fn: Data): Observable<Data>;
20
+ export {};
@@ -0,0 +1 @@
1
+ export { type Adapter } from './persistance/adapters/Adapter';
@@ -0,0 +1,6 @@
1
+ export interface Adapter {
2
+ getItem: (key: string) => Promise<unknown>;
3
+ setItem: (key: string, value: any) => Promise<unknown>;
4
+ removeItem: (key: string) => Promise<unknown>;
5
+ clear: () => Promise<unknown>;
6
+ }
@@ -0,0 +1,14 @@
1
+ import { Adapter } from './Adapter';
2
+ export declare class MockAdapter implements Adapter {
3
+ storage: Record<string, any>;
4
+ config: {
5
+ resolve: boolean;
6
+ };
7
+ constructor(storage?: Record<string, any>, config?: {
8
+ resolve: boolean;
9
+ });
10
+ getItem(key: string): Promise<any>;
11
+ setItem(_: string, __: any): Promise<unknown>;
12
+ removeItem(_: string): Promise<unknown>;
13
+ clear(): Promise<unknown>;
14
+ }
@@ -1,4 +1,4 @@
1
- import { Adapter } from '../types';
1
+ import { Adapter } from './Adapter';
2
2
  export declare const createLocalStorageAdapter: ({ key }?: {
3
3
  key?: string;
4
4
  }) => Adapter;
@@ -1,4 +1,4 @@
1
- import { Adapter } from '../types';
1
+ import { Adapter } from './Adapter';
2
2
  export declare const createLocalforageAdapter: (forage: {
3
3
  getItem: (key: string) => Promise<string | null>;
4
4
  setItem: (key: string, value: string) => Promise<string>;
@@ -0,0 +1,11 @@
1
+ import { Adapter } from './adapters/Adapter';
2
+ import { SignalPersistenceConfig, PersistanceEntry } from './types';
3
+ export declare const getNormalizedPersistanceValue: (unknownValue: unknown) => PersistanceEntry | undefined;
4
+ export declare const persistValue: ({ adapter, config }: {
5
+ adapter: Adapter;
6
+ config: SignalPersistenceConfig<any>;
7
+ }) => import('rxjs').Observable<unknown>;
8
+ export declare function hydrateValueToSignal({ adapter, config }: {
9
+ adapter: Adapter;
10
+ config: SignalPersistenceConfig<any>;
11
+ }): import('rxjs').Observable<unknown>;
@@ -0,0 +1,20 @@
1
+ import { SignalPersistenceConfig } from './types';
2
+ import { Signal } from '../signal';
3
+ import { Adapter } from './adapters/Adapter';
4
+ export declare function persistSignals({ entries, onHydrated, adapter }: {
5
+ entries: Array<SignalPersistenceConfig<Signal<any, any, string>>>;
6
+ /**
7
+ * Triggered after first successful hydrate
8
+ */
9
+ onHydrated?: () => void;
10
+ /**
11
+ * Requires a stable instance otherwise the hydration
12
+ * process will start again. This is useful when you
13
+ * need to change adapter during runtime.
14
+ */
15
+ adapter: Adapter;
16
+ }): import('rxjs').Observable<{
17
+ type: "hydrated";
18
+ } | {
19
+ type: "persisted";
20
+ }>;
@@ -1,11 +1,5 @@
1
1
  import { SignalValue, Signal } from '../signal';
2
2
  import { IDENTIFIER_PERSISTANCE_KEY } from './constants';
3
- export interface Adapter {
4
- getItem: (key: string) => Promise<unknown>;
5
- setItem: (key: string, value: any) => Promise<unknown>;
6
- removeItem: (key: string) => Promise<unknown>;
7
- clear: () => Promise<unknown>;
8
- }
9
3
  export interface PersistanceEntry {
10
4
  value: unknown;
11
5
  migrationVersion?: number;
@@ -0,0 +1,29 @@
1
+ import { SignalPersistenceConfig } from '../persistance/types';
2
+ import { Adapter } from '../persistance/adapters/Adapter';
3
+ /**
4
+ * Make sure to pass stable reference of entries and adapter if you don't
5
+ * intentionally want to start over the process.
6
+ *
7
+ * `isHydrated` will be `true` after the first successful hydration. This value
8
+ * will be reset as soon as the adapter reference changes.
9
+ */
10
+ export declare function usePersistSignals({ entries, onHydrated, adapter }: {
11
+ /**
12
+ * Passing a new list of entries will start over the process
13
+ * once the current one is finished. Use a stable reference to avoid
14
+ * inifite loop.
15
+ */
16
+ entries?: Array<SignalPersistenceConfig<any>>;
17
+ /**
18
+ * Triggered after first successful hydrate
19
+ */
20
+ onHydrated?: () => void;
21
+ /**
22
+ * Passing a new adapter reference will start over the process
23
+ * once the current one is finished. Use a stable reference to avoid
24
+ * inifite loop.
25
+ */
26
+ adapter?: Adapter;
27
+ }): {
28
+ isHydrated: boolean;
29
+ };
@@ -1,7 +1,7 @@
1
- import { Config } from './signal';
1
+ import { Config } from '../signal';
2
2
  /**
3
3
  * Use it when:
4
4
  * - you need reactive state
5
5
  * - you don't need global state
6
6
  */
7
- export declare const useSignal: <T>(config: Config<T>) => readonly [T, import('./signal').Signal<T, T, undefined>];
7
+ export declare const useSignal: <T>(config: Config<T>) => readonly [T, import('../signal').Signal<T, T, undefined>];
@@ -1,4 +1,4 @@
1
- import { ReadOnlySignal, Signal } from './signal';
1
+ import { ReadOnlySignal, Signal } from '../signal';
2
2
  export declare function useSignalValue<DefaultValue, Value, Key, SelectValue>(signal: Signal<DefaultValue, Value, Key>, selector: (value: DefaultValue) => SelectValue): SelectValue;
3
3
  export declare function useSignalValue<DefaultValue, Value, Key>(signal: Signal<DefaultValue, Value, Key>): DefaultValue;
4
4
  export declare function useSignalValue<Value>(signal: ReadOnlySignal<Value>): Value;
@@ -1,7 +1,7 @@
1
1
  import { render } from '@testing-library/react';
2
2
  import { QueryClient, QueryClientConfig } from '../lib/queries/client/QueryClient';
3
3
  import { default as React } from 'react';
4
- export declare const waitForTimeout: (timeout: number) => Promise<unknown>;
4
+ export declare const waitForTimeout: (timeout: number) => Promise<undefined>;
5
5
  /**
6
6
  * @see https://github.com/TanStack/query/blob/main/packages/react-query/src/__tests__/utils.tsx
7
7
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "reactjrx",
3
3
  "private": false,
4
- "version": "1.99.0",
4
+ "version": "1.101.1",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"
@@ -28,7 +28,7 @@
28
28
  "preview": "vite preview",
29
29
  "prepublishOnly": "npm run build",
30
30
  "semantic-release": "semantic-release",
31
- "test": "vitest",
31
+ "test": "vitest --typecheck",
32
32
  "test:ci": "vitest run",
33
33
  "tsc": "tsc",
34
34
  "lint": "eslint '**/*.{js,ts,tsx}'",
@@ -61,7 +61,7 @@
61
61
  "rollup-plugin-node-externals": "^7.0.1",
62
62
  "rxjs": "^7.8.0",
63
63
  "semantic-release": "^24.1.1",
64
- "typescript": "5.6.2",
64
+ "typescript": "^5.6.2",
65
65
  "vite": "^5.1.3",
66
66
  "vite-plugin-dts": "^4.2.1",
67
67
  "vitest": "^1.3.0"
@@ -1,2 +0,0 @@
1
- import { PersistanceEntry } from './types';
2
- export declare const getNormalizedPersistanceValue: (unknownValue: unknown) => PersistanceEntry | undefined;
@@ -1,16 +0,0 @@
1
- import { Adapter, SignalPersistenceConfig } from './types';
2
- export declare function usePersistSignals({ entries, onReady, adapter }: {
3
- entries?: Array<SignalPersistenceConfig<any>>;
4
- /**
5
- * Triggered after first successful hydrate
6
- */
7
- onReady?: () => void;
8
- /**
9
- * Requires a stable instance otherwise the hydration
10
- * process will start again. This is useful when you
11
- * need to change adapter during runtime.
12
- */
13
- adapter?: Adapter;
14
- }): {
15
- isHydrated: boolean;
16
- };