Skip to content

Commit a7aa104

Browse files
committed
WIP need to base off V+ branch
1 parent 366bbdf commit a7aa104

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

packages/jsapi-bootstrap/src/useObjectFetch.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createContext, useContext, useEffect, useState } from 'react';
22
import type { dh } from '@deephaven/jsapi-types';
3+
import { ObjectFetcherContext } from './useObjectFetcher';
34

45
/** Function for unsubscribing from a given subscription */
56
export type UnsubscribeFunction = () => void;
@@ -23,6 +24,10 @@ export type ObjectFetchUpdate<T = unknown> = {
2324
error: unknown | null;
2425
};
2526

27+
export type ObjectFetchUpdateCallback<T = unknown> = (
28+
update: ObjectFetchUpdate<T>
29+
) => void;
30+
2631
/** ObjectFetchManager for managing a subscription to an object using a VariableDescriptor */
2732
export type ObjectFetchManager = {
2833
/**
@@ -33,7 +38,7 @@ export type ObjectFetchManager = {
3338
*/
3439
subscribe: <T = unknown>(
3540
descriptor: dh.ide.VariableDescriptor,
36-
onUpdate: (update: ObjectFetchUpdate<T>) => void
41+
onUpdate: ObjectFetchUpdateCallback<T>
3742
) => UnsubscribeFunction;
3843
};
3944

@@ -58,14 +63,22 @@ export function useObjectFetch<T = unknown>(
5863
})
5964
);
6065

66+
const objectFetcher = useContext(ObjectFetcherContext);
6167
const objectFetchManager = useContext(ObjectFetchManagerContext);
6268

6369
useEffect(() => {
6470
if (objectFetchManager == null) {
65-
setCurrentUpdate({
66-
fetch: null,
67-
error: new Error('No ObjectFetchManager available in context'),
68-
});
71+
if (objectFetcher == null) {
72+
setCurrentUpdate({
73+
fetch: null,
74+
error: new Error('No ObjectFetchManager available in context'),
75+
});
76+
} else {
77+
setCurrentUpdate({
78+
fetch: () => objectFetcher(descriptor),
79+
error: null,
80+
});
81+
}
6982
return;
7083
}
7184
// Signal that we're still loading
@@ -74,7 +87,7 @@ export function useObjectFetch<T = unknown>(
7487
error: null,
7588
});
7689
return objectFetchManager.subscribe(descriptor, setCurrentUpdate);
77-
}, [descriptor, objectFetchManager]);
90+
}, [descriptor, objectFetcher, objectFetchManager]);
7891

7992
return currentUpdate;
8093
}

0 commit comments

Comments
 (0)