@equinor/fusion-observable
Advanced tools
Comparing version 0.2.0 to 0.3.0
import { useEffect, useMemo, useState } from 'react'; | ||
import { share, Subject } from 'rxjs'; | ||
import { QueryClient } from '../query'; | ||
import { QueryClient, QueryStatus } from '../query'; | ||
import { useObservableSelector } from './useObservableSelector'; | ||
@@ -14,9 +14,11 @@ import { useObservableState } from './useObservableState'; | ||
}; | ||
export const useQueryClient = (queryFn, options) => { | ||
const { data$, status$, ...obj } = useQueryClient$(queryFn, options); | ||
export const useQueryClientStreamResult = (result) => { | ||
const { data$, status$, ...obj } = result; | ||
const data = useObservableState(data$); | ||
const status = useObservableState(status$); | ||
return { ...obj, data, status }; | ||
const status = useObservableState(status$) ?? QueryStatus.IDLE; | ||
const isLoading = useMemo(() => status === QueryStatus.ACTIVE, [status]); | ||
return Object.assign(obj, { data, status, isLoading }); | ||
}; | ||
export const useQueryClient = (queryFn, options) => useQueryClientStreamResult(useQueryClient$(queryFn, options)); | ||
export default useQueryClient; | ||
//# sourceMappingURL=useQueryClient.js.map |
@@ -1,14 +0,24 @@ | ||
import { QueryClient, QueryFn, QueryOptions } from '../query'; | ||
export declare const useQueryClient$: <TType, TArgs>(queryFn: QueryFn<TType, TArgs>, options?: QueryOptions<TType, TArgs> | undefined) => { | ||
import { Observable } from 'rxjs'; | ||
import { QueryClient, QueryFn, QueryOptions, QueryStatus } from '../query'; | ||
export declare type UseQueryClientStreamResult<TType, TArgs> = { | ||
client: QueryClient<TType, TArgs>; | ||
data$: import("rxjs").Observable<TType>; | ||
status$: import("rxjs").Observable<import("../query").QueryStatus>; | ||
query: (q: TArgs) => void; | ||
data$: Observable<TType>; | ||
status$: Observable<QueryStatus>; | ||
query: (args: TArgs) => void; | ||
}; | ||
export declare const useQueryClient: <TType, TArgs>(queryFn: QueryFn<TType, TArgs>, options?: QueryOptions<TType, TArgs> | undefined) => { | ||
export declare type UseQueryClientResult<TType, TArgs> = Omit<UseQueryClientStreamResult<TType, TArgs>, 'data$' | 'status$'> & { | ||
data: TType | undefined; | ||
status: import("../query").QueryStatus | undefined; | ||
client: QueryClient<TType, TArgs>; | ||
query: (q: TArgs) => void; | ||
status: QueryStatus; | ||
isLoading: boolean; | ||
}; | ||
export declare const useQueryClient$: <TType, TArgs>(queryFn: QueryFn<TType, TArgs>, options?: QueryOptions<TType, TArgs> | undefined) => UseQueryClientStreamResult<TType, TArgs>; | ||
export declare const useQueryClientStreamResult: <TType, TArgs extends { | ||
data$: Observable<TType>; | ||
status$: Observable<QueryStatus>; | ||
}>(result: TArgs) => { | ||
data: TType | undefined; | ||
status: QueryStatus; | ||
isLoading: boolean; | ||
} & Omit<TArgs, "data$" | "$status">; | ||
export declare const useQueryClient: <TType, TArgs>(queryFn: QueryFn<TType, TArgs>, options?: QueryOptions<TType, TArgs> | undefined) => UseQueryClientResult<TType, TArgs>; | ||
export default useQueryClient; |
{ | ||
"name": "@equinor/fusion-observable", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "WIP", | ||
@@ -84,3 +84,3 @@ "private": false, | ||
}, | ||
"gitHead": "5f5ceed6b3f4f6ab12036f1f2953d293dff86cae" | ||
"gitHead": "472e06a77cfccc723b0fb88e628d10df18eab5e1" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
132297
820