[#128] generic data provider improvments

This commit is contained in:
Bartłomiej Głownia 2022-03-28 17:14:00 +02:00
parent 6e6a79d8e3
commit 7ba74eeafd
2 changed files with 3 additions and 3 deletions

View File

@ -22,7 +22,7 @@ export interface Subscribe<Data, Delta> {
callback: UpdateCallback<Data, Delta>,
client: ApolloClient<object>,
variables?: OperationVariables
): void;
): () => void;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any

View File

@ -5,7 +5,7 @@ import type { Subscribe } from '@vegaprotocol/graphql';
export function useDataProvider<Data, Delta>(
dataProvider: Subscribe<Data, Delta>,
update: (delta: Delta) => boolean = () => false,
update?: (delta: Delta) => boolean,
variables?: OperationVariables
) {
const client = useApolloClient();
@ -18,7 +18,7 @@ export function useDataProvider<Data, Delta>(
setError(error);
setLoading(loading);
if (!error && !loading) {
if (!initialized.current || !delta || !update(delta)) {
if (!initialized.current || !delta || !update || !update(delta)) {
initialized.current = true;
setData(data);
}