@equinor/fusion-query
Advanced tools
Comparing version 0.3.1 to 1.0.0
@@ -1,17 +0,9 @@ | ||
import { useCallback, useMemo, useState } from 'react'; | ||
import { debounce, debounceTime, Subject, switchMap, tap } from 'rxjs'; | ||
import { useObservableState } from '@equinor/fusion-observable/react'; | ||
import { useState } from 'react'; | ||
import { useDebounce } from '@equinor/fusion-observable/react'; | ||
import Query from '../Query'; | ||
export const useDebounceQuery = (clientOrClientCtor, options) => { | ||
const [client] = useState(() => clientOrClientCtor instanceof Query ? clientOrClientCtor : new Query(clientOrClientCtor)); | ||
const [querying, setQuerying] = useState(false); | ||
const [queuer] = useState(() => { var _a; return (_a = options === null || options === void 0 ? void 0 : options.queuer) !== null && _a !== void 0 ? _a : new Subject(); }); | ||
const query = useCallback((args) => queuer.next(args), [queuer]); | ||
const debounceFn = useMemo(() => typeof options.debounce === 'function' | ||
? debounce(options.debounce) | ||
: debounceTime(options.debounce), [options.debounce]); | ||
const value = useObservableState(useMemo(() => queuer.pipe(debounceFn, tap(() => setQuerying(true)), switchMap(({ args, options }) => client.query(args, options)), tap(() => setQuerying(false))), [client]), options === null || options === void 0 ? void 0 : options.initial); | ||
return { value, query, querying }; | ||
return useDebounce(client.query.bind(client), options); | ||
}; | ||
export default useDebounceQuery; | ||
//# sourceMappingURL=useDebounceQuery.js.map |
@@ -1,19 +0,8 @@ | ||
import { debounce, ObservableInput, Subject } from 'rxjs'; | ||
import type { ObservableType } from '@equinor/fusion-observable'; | ||
import { UseDebounceOptions } from '@equinor/fusion-observable/react'; | ||
import Query, { QueryCtorOptions } from '../Query'; | ||
import { QueryOptions } from '../types'; | ||
type UseDebounceQueryArgs<TType, TArgs> = { | ||
args: TArgs; | ||
options?: QueryOptions<TType, TArgs>; | ||
export declare const useDebounceQuery: <TType, TArgs>(clientOrClientCtor: Query<TType, TArgs> | QueryCtorOptions<TType, TArgs>, options: UseDebounceOptions<[TArgs]>) => { | ||
value$: import("rxjs").Observable<import("..").QueryTaskCached<TType, TArgs> | import("../client").QueryTaskCompleted<TType, TArgs>>; | ||
next: (args_0: TArgs) => void; | ||
idle: boolean; | ||
}; | ||
type UseDebounceQueryValue<TType, TArgs> = ObservableType<ReturnType<Query<TType, TArgs>['query']>>; | ||
export declare const useDebounceQuery: <TType, TArgs>(clientOrClientCtor: Query<TType, TArgs> | QueryCtorOptions<TType, TArgs>, options: { | ||
debounce: number | ((value: UseDebounceQueryArgs<TType, TArgs>) => ObservableInput<unknown>); | ||
initial?: import("../types").QueryTaskCached<TType, TArgs> | import("../client").QueryTaskCompleted<TType, TArgs> | undefined; | ||
queuer?: Subject<UseDebounceQueryArgs<TType, TArgs>> | undefined; | ||
}) => { | ||
value: import("../types").QueryTaskCached<TType, TArgs> | import("../client").QueryTaskCompleted<TType, TArgs> | undefined; | ||
query: (args: UseDebounceQueryArgs<TType, TArgs>) => void; | ||
querying: boolean; | ||
}; | ||
export default useDebounceQuery; |
{ | ||
"name": "@equinor/fusion-query", | ||
"version": "0.3.1", | ||
"version": "1.0.0", | ||
"description": "WIP", | ||
@@ -57,3 +57,3 @@ "private": false, | ||
"dependencies": { | ||
"@equinor/fusion-observable": "^2.5.0", | ||
"@equinor/fusion-observable": "^3.0.0", | ||
"immer": "^9.0.16", | ||
@@ -81,3 +81,3 @@ "rxjs": "^7.5.7", | ||
}, | ||
"gitHead": "909e48f515aa842e15eaeb26a7f75c160da39e84" | ||
"gitHead": "b93e25b79c3b34ee46bd3a16b059e850acdffe95" | ||
} |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
159133
1003
+ Added@equinor/fusion-observable@3.0.4(transitive)
- Removed@equinor/fusion-observable@2.5.0(transitive)