[#128] generic data provider improvments
This commit is contained in:
parent
6e6a79d8e3
commit
7ba74eeafd
@ -22,7 +22,7 @@ export interface Subscribe<Data, Delta> {
|
|||||||
callback: UpdateCallback<Data, Delta>,
|
callback: UpdateCallback<Data, Delta>,
|
||||||
client: ApolloClient<object>,
|
client: ApolloClient<object>,
|
||||||
variables?: OperationVariables
|
variables?: OperationVariables
|
||||||
): void;
|
): () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
@ -5,7 +5,7 @@ import type { Subscribe } from '@vegaprotocol/graphql';
|
|||||||
|
|
||||||
export function useDataProvider<Data, Delta>(
|
export function useDataProvider<Data, Delta>(
|
||||||
dataProvider: Subscribe<Data, Delta>,
|
dataProvider: Subscribe<Data, Delta>,
|
||||||
update: (delta: Delta) => boolean = () => false,
|
update?: (delta: Delta) => boolean,
|
||||||
variables?: OperationVariables
|
variables?: OperationVariables
|
||||||
) {
|
) {
|
||||||
const client = useApolloClient();
|
const client = useApolloClient();
|
||||||
@ -18,7 +18,7 @@ export function useDataProvider<Data, Delta>(
|
|||||||
setError(error);
|
setError(error);
|
||||||
setLoading(loading);
|
setLoading(loading);
|
||||||
if (!error && !loading) {
|
if (!error && !loading) {
|
||||||
if (!initialized.current || !delta || !update(delta)) {
|
if (!initialized.current || !delta || !update || !update(delta)) {
|
||||||
initialized.current = true;
|
initialized.current = true;
|
||||||
setData(data);
|
setData(data);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user