@effectify/react-query 1.0.0 → 1.0.1-beta.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/package.json +5 -3
- package/dist/src/lib/internal/make-use-rx-subsciption-ref.d.ts +4 -19
- package/dist/src/lib/internal/make-use-rx-subsciption-ref.js +14 -24
- package/dist/src/lib/internal/make-use-rx-subscribe.d.ts +1 -1
- package/dist/src/lib/internal/make-use-rx-subscribe.js +14 -22
- package/dist/src/lib/tanstack-query-effect.d.ts +2 -2
- package/dist/src/lib/types.d.ts +0 -5
- package/package.json +5 -3
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effectify/react-query",
|
|
3
|
-
"version": "1.0.0",
|
|
3
|
+
"version": "1.0.1-beta.0",
|
|
4
4
|
"description": "Integration of Effect with TanStack Query for React",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -34,10 +34,12 @@
|
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"typescript": "catalog:",
|
|
36
36
|
"@types/react": "catalog:",
|
|
37
|
-
"
|
|
37
|
+
"@types/react-dom": "catalog:",
|
|
38
|
+
"effect": "catalog:",
|
|
39
|
+
"react-dom": "catalog:"
|
|
38
40
|
},
|
|
39
41
|
"optionalDependencies": {},
|
|
40
42
|
"peerDependencies": {
|
|
41
|
-
"effect": "^
|
|
43
|
+
"effect": "^4.0.0-beta"
|
|
42
44
|
}
|
|
43
45
|
}
|
|
@@ -1,20 +1,5 @@
|
|
|
1
|
-
import { type Context } from "react";
|
|
2
1
|
import type * as ManagedRuntime from "effect/ManagedRuntime";
|
|
3
|
-
import
|
|
4
|
-
import type
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
* This hook is temporarily disabled due to significant API changes in Effect v4:
|
|
9
|
-
* - SubscriptionRef.SubscriptionRefTypeId was removed
|
|
10
|
-
* - Stream APIs reorganized under effect/unstable/*
|
|
11
|
-
* - Migration documentation is incomplete (see Effect-TS/effect-smol#1378)
|
|
12
|
-
*
|
|
13
|
-
* The core functionality (useEffectQuery, useEffectMutation) works with v4.
|
|
14
|
-
* This advanced subscription feature will be revisited when v4 documentation
|
|
15
|
-
* is complete or when the beta stabilizes.
|
|
16
|
-
*
|
|
17
|
-
* TODO: Re-enable after Effect v4 stable release and documentation update
|
|
18
|
-
* @deprecated Temporarily disabled during Effect v4 beta migration
|
|
19
|
-
*/
|
|
20
|
-
export declare const makeUseRxSubscriptionRef: <R, E>(RuntimeContext: Context<ManagedRuntime.ManagedRuntime<R, E> | null>) => <A, E2>(_subscribable: Subscribable<A, E2> | Effect.Effect<Subscribable<A, E2>, never, R> | Effect.Effect<unknown, never, R>, _onNext: (value: A) => void, _opts?: SubscriptionOptions) => A;
|
|
2
|
+
import * as SubscriptionRef from "effect/SubscriptionRef";
|
|
3
|
+
import { type Context } from "react";
|
|
4
|
+
import type { SubscriptionOptions } from "../types.js";
|
|
5
|
+
export declare const makeUseRxSubscriptionRef: <R, E>(RuntimeContext: Context<ManagedRuntime.ManagedRuntime<R, E> | null>) => <A>(ref: SubscriptionRef.SubscriptionRef<A>, onNext: (value: A) => void, opts?: SubscriptionOptions) => A;
|
|
@@ -1,25 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* @deprecated Temporarily disabled during Effect v4 beta migration
|
|
16
|
-
*/
|
|
17
|
-
export const makeUseRxSubscriptionRef = (RuntimeContext) => (_subscribable, _onNext, _opts) => {
|
|
18
|
-
const runtime = useContext(RuntimeContext);
|
|
19
|
-
if (!runtime) {
|
|
20
|
-
throw new Error("Runtime context not found. Make sure to wrap your app with RuntimeProvider");
|
|
21
|
-
}
|
|
22
|
-
throw new Error("useRxSubscriptionRef is temporarily disabled during Effect v4 beta migration. " +
|
|
23
|
-
"Please use useEffectQuery or useEffectMutation instead, or wait for v4 stable release. " +
|
|
24
|
-
"See: https://github.com/Effect-TS/effect-smol/issues/1378");
|
|
1
|
+
import * as SubscriptionRef from "effect/SubscriptionRef";
|
|
2
|
+
import { useCallback, useMemo, useRef } from "react";
|
|
3
|
+
import { makeUseRxSubscribe } from "./make-use-rx-subscribe.js";
|
|
4
|
+
export const makeUseRxSubscriptionRef = (RuntimeContext) => {
|
|
5
|
+
const useRxSubscribe = makeUseRxSubscribe(RuntimeContext);
|
|
6
|
+
return (ref, onNext, opts) => {
|
|
7
|
+
const changes = useMemo(() => SubscriptionRef.changes(ref), [ref]);
|
|
8
|
+
const skipInitial = opts?.skipInitial ?? true;
|
|
9
|
+
const onNextRef = useRef(onNext);
|
|
10
|
+
onNextRef.current = onNext;
|
|
11
|
+
const handleNext = useCallback((value) => onNextRef.current(value), []);
|
|
12
|
+
const currentValue = SubscriptionRef.getUnsafe(ref);
|
|
13
|
+
return useRxSubscribe(changes, currentValue, handleNext, undefined, skipInitial);
|
|
14
|
+
};
|
|
25
15
|
};
|
|
@@ -2,4 +2,4 @@ import * as Effect from "effect/Effect";
|
|
|
2
2
|
import type * as ManagedRuntime from "effect/ManagedRuntime";
|
|
3
3
|
import * as Stream from "effect/Stream";
|
|
4
4
|
import { type Context } from "react";
|
|
5
|
-
export declare const makeUseRxSubscribe: <R, E>(RuntimeContext: Context<ManagedRuntime.ManagedRuntime<R, E> | null>) => <E2, A>(stream: Stream.Stream<A, E2, R> | Effect.Effect<Stream.Stream<A, E2, R>, E2, R>, initialValue: A, onNext: (value: A) => void, onError?: (error: E2) => void) => A
|
|
5
|
+
export declare const makeUseRxSubscribe: <R, E>(RuntimeContext: Context<ManagedRuntime.ManagedRuntime<R, E> | null>) => <E2, A>(stream: Stream.Stream<A, E2, R> | Effect.Effect<Stream.Stream<A, E2, R>, E2, R>, initialValue: A, onNext: (value: A) => void, onError?: (error: E2) => void, skipInitial?: boolean) => A;
|
|
@@ -1,40 +1,32 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect";
|
|
2
|
-
import * as Exit from "effect/Exit";
|
|
3
|
-
import * as Fiber from "effect/Fiber";
|
|
4
2
|
import * as Stream from "effect/Stream";
|
|
5
|
-
import { useContext, useEffect,
|
|
3
|
+
import { useContext, useEffect, useMemo, useState } from "react";
|
|
6
4
|
export const makeUseRxSubscribe = (RuntimeContext) => {
|
|
7
|
-
return (stream, initialValue, onNext, onError) => {
|
|
5
|
+
return (stream, initialValue, onNext, onError, skipInitial = false) => {
|
|
8
6
|
const runtime = useContext(RuntimeContext);
|
|
9
7
|
if (!runtime) {
|
|
10
8
|
throw new Error("Runtime context not found. Make sure to wrap your app with RuntimeProvider");
|
|
11
9
|
}
|
|
12
|
-
const [value, setValue] = useState(initialValue);
|
|
13
|
-
const
|
|
14
|
-
const finalStream = Effect.isEffect(stream)
|
|
15
|
-
? Stream.unwrap(stream)
|
|
16
|
-
: stream;
|
|
10
|
+
const [value, setValue] = useState(() => initialValue);
|
|
11
|
+
const finalStream = useMemo(() => (Effect.isEffect(stream) ? Stream.unwrap(stream) : stream), [stream]);
|
|
17
12
|
useEffect(() => {
|
|
13
|
+
let isInitial = true;
|
|
18
14
|
const subscription = finalStream.pipe(Stream.tap((a) => Effect.sync(() => {
|
|
19
15
|
setValue(a);
|
|
16
|
+
if (isInitial) {
|
|
17
|
+
isInitial = false;
|
|
18
|
+
if (skipInitial)
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
20
21
|
onNext(a);
|
|
21
22
|
})), Stream.catch((e) => Stream.fromEffect(Effect.sync(() => {
|
|
22
23
|
onError?.(e);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
runtime.runCallback(subscription, {
|
|
26
|
-
onExit: (exit) => {
|
|
27
|
-
if (Exit.isSuccess(exit)) {
|
|
28
|
-
fiberRef.current = exit.value;
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
});
|
|
24
|
+
}))), Stream.runDrain);
|
|
25
|
+
const cancel = runtime.runCallback(subscription);
|
|
32
26
|
return () => {
|
|
33
|
-
|
|
34
|
-
runtime.runCallback(Fiber.interrupt(fiberRef.current));
|
|
35
|
-
}
|
|
27
|
+
cancel();
|
|
36
28
|
};
|
|
37
|
-
}, [finalStream, runtime, onNext, onError]);
|
|
29
|
+
}, [finalStream, runtime, onNext, onError, skipInitial]);
|
|
38
30
|
return value;
|
|
39
31
|
};
|
|
40
32
|
};
|
|
@@ -14,8 +14,8 @@ export declare const tanstackQueryEffect: <R, E>({ layer, queryClient, }: {
|
|
|
14
14
|
useRuntime: () => ManagedRuntime.ManagedRuntime<R, E>;
|
|
15
15
|
useEffectQuery: <TData, TError extends import("./types.js").EffectfulError, TQueryKey extends import("./types.js").QueryKey = import("./types.js").QueryKey>({ gcTime, staleTime, ...options }: import("./types.js").EffectfulQueryOptions<TData, TError, R, TQueryKey>) => import("@tanstack/react-query").UseQueryResult<TData, Error>;
|
|
16
16
|
useEffectMutation: <TData, TError_1 extends import("./types.js").EffectfulError, TVariables>(options: import("./types.js").EffectfulMutationOptions<TData, TError_1, TVariables, R>) => import("@tanstack/react-query").UseMutationResult<TData, Error, TVariables>;
|
|
17
|
-
useRxSubscribe: <E2_1, A>(stream: import("effect/Stream").Stream<A, E2_1, R> | Effect.Effect<import("effect/Stream").Stream<A, E2_1, R>, E2_1, R>, initialValue: A, onNext: (value: A) => void, onError?: ((error: E2_1) => void) | undefined) => A
|
|
18
|
-
useRxSubscriptionRef: <A_1
|
|
17
|
+
useRxSubscribe: <E2_1, A>(stream: import("effect/Stream").Stream<A, E2_1, R> | Effect.Effect<import("effect/Stream").Stream<A, E2_1, R>, E2_1, R>, initialValue: A, onNext: (value: A) => void, onError?: ((error: E2_1) => void) | undefined, skipInitial?: boolean) => A;
|
|
18
|
+
useRxSubscriptionRef: <A_1>(ref: import("effect/SubscriptionRef").SubscriptionRef<A_1>, onNext: (value: A_1) => void, opts?: import("./types.js").SubscriptionOptions) => A_1;
|
|
19
19
|
createQueryDataHelpers: <TData, TVariables_1 = void>(queryKey: (variables: TVariables_1) => readonly [string, ...unknown[]]) => {
|
|
20
20
|
removeQuery: (variables: TVariables_1) => void;
|
|
21
21
|
removeAllQueries: () => void;
|
package/dist/src/lib/types.d.ts
CHANGED
|
@@ -16,11 +16,6 @@ export type EffectfulQueryOptions<TData, TError, R, TQueryKey extends QueryKey =
|
|
|
16
16
|
staleTime?: number;
|
|
17
17
|
gcTime?: number;
|
|
18
18
|
};
|
|
19
|
-
export interface Subscribable<A, E = never> {
|
|
20
|
-
readonly changes: unknown;
|
|
21
|
-
readonly get: () => A;
|
|
22
|
-
readonly _errorType?: E;
|
|
23
|
-
}
|
|
24
19
|
export interface SubscriptionOptions {
|
|
25
20
|
readonly skipInitial?: boolean;
|
|
26
21
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effectify/react-query",
|
|
3
|
-
"version": "1.0.0",
|
|
3
|
+
"version": "1.0.1-beta.0",
|
|
4
4
|
"description": "Integration of Effect with TanStack Query for React",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -34,10 +34,12 @@
|
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"typescript": "npm:@typescript/typescript6@6.0.2",
|
|
36
36
|
"@types/react": "19.2.17",
|
|
37
|
-
"
|
|
37
|
+
"@types/react-dom": "19.2.3",
|
|
38
|
+
"effect": "4.0.0-rc.111",
|
|
39
|
+
"react-dom": "19.2.7"
|
|
38
40
|
},
|
|
39
41
|
"optionalDependencies": {},
|
|
40
42
|
"peerDependencies": {
|
|
41
|
-
"effect": "^
|
|
43
|
+
"effect": "^4.0.0-beta"
|
|
42
44
|
}
|
|
43
45
|
}
|