@deephaven/jsapi-bootstrap 0.78.1-use-widget.4 → 0.78.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/useObjectFetch.d.ts +20 -14
- package/dist/useObjectFetch.d.ts.map +1 -1
- package/dist/useObjectFetch.js +22 -23
- package/dist/useObjectFetch.js.map +1 -1
- package/dist/useWidget.d.ts +9 -5
- package/dist/useWidget.d.ts.map +1 -1
- package/dist/useWidget.js +18 -11
- package/dist/useWidget.js.map +1 -1
- package/package.json +7 -7
package/dist/useObjectFetch.d.ts
CHANGED
|
@@ -2,31 +2,37 @@
|
|
|
2
2
|
import type { dh } from '@deephaven/jsapi-types';
|
|
3
3
|
/** Function for unsubscribing from a given subscription */
|
|
4
4
|
export type UnsubscribeFunction = () => void;
|
|
5
|
+
/** Update when the ObjectFetch is still loading */
|
|
6
|
+
export type ObjectFetchLoading = {
|
|
7
|
+
status: 'loading';
|
|
8
|
+
};
|
|
9
|
+
/** Update when the ObjectFetch has errored */
|
|
10
|
+
export type ObjectFetchError = {
|
|
11
|
+
error: NonNullable<unknown>;
|
|
12
|
+
status: 'error';
|
|
13
|
+
};
|
|
14
|
+
/** Update when the object is ready */
|
|
15
|
+
export type ObjectFetchReady<T> = {
|
|
16
|
+
fetch: () => Promise<T>;
|
|
17
|
+
status: 'ready';
|
|
18
|
+
};
|
|
5
19
|
/**
|
|
6
|
-
* Update with the current `fetch`
|
|
20
|
+
* Update with the current `fetch` function and status of the object.
|
|
7
21
|
* - If both `fetch` and `error` are `null`, it is still loading the fetcher
|
|
8
22
|
* - If `fetch` is not `null`, the object is ready to be fetched
|
|
9
23
|
* - If `error` is not `null`, there was an error loading the object
|
|
10
24
|
*/
|
|
11
|
-
export type ObjectFetchUpdate<T = unknown> =
|
|
12
|
-
/**
|
|
13
|
-
* Function to fetch the object. If `null`, the object is still loading or there was an error.
|
|
14
|
-
*/
|
|
15
|
-
fetch: (() => Promise<T>) | null;
|
|
16
|
-
/**
|
|
17
|
-
* Error that occurred while fetching the object. If `null`, there was no error.
|
|
18
|
-
* Will automatically retry when possible while the subscribed.
|
|
19
|
-
*/
|
|
20
|
-
error: unknown | null;
|
|
21
|
-
};
|
|
25
|
+
export type ObjectFetchUpdate<T = unknown> = ObjectFetchLoading | ObjectFetchError | ObjectFetchReady<T>;
|
|
22
26
|
export type ObjectFetchUpdateCallback<T = unknown> = (update: ObjectFetchUpdate<T>) => void;
|
|
23
27
|
/** ObjectFetchManager for managing a subscription to an object using a VariableDescriptor */
|
|
24
28
|
export type ObjectFetchManager = {
|
|
25
29
|
/**
|
|
30
|
+
* Subscribe to the fetch function for an object using a variable descriptor.
|
|
31
|
+
* It's possible that the fetch function changes over time, due to disconnection/reconnection, starting/stopping of applications that the object may be associated with, etc.
|
|
26
32
|
*
|
|
27
|
-
* @param descriptor Descriptor object
|
|
33
|
+
* @param descriptor Descriptor object of the object to fetch. Can be extended by a specific implementation to include more details necessary for the ObjectManager.
|
|
28
34
|
* @param onUpdate Callback function to be called when the object is updated.
|
|
29
|
-
* @returns An unsubscribe function to stop listening for updates and clean up the object.
|
|
35
|
+
* @returns An unsubscribe function to stop listening for fetch updates and clean up the object.
|
|
30
36
|
*/
|
|
31
37
|
subscribe: <T = unknown>(descriptor: dh.ide.VariableDescriptor, onUpdate: ObjectFetchUpdateCallback<T>) => UnsubscribeFunction;
|
|
32
38
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useObjectFetch.d.ts","sourceRoot":"","sources":["../src/useObjectFetch.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"useObjectFetch.d.ts","sourceRoot":"","sources":["../src/useObjectFetch.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;AAEjD,2DAA2D;AAC3D,MAAM,MAAM,mBAAmB,GA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3
3
|
/** Function for unsubscribing from a given subscription */
|
|
4
|
+
|
|
5
|
+
/** Update when the ObjectFetch is still loading */
|
|
6
|
+
|
|
7
|
+
/** Update when the ObjectFetch has errored */
|
|
8
|
+
|
|
9
|
+
/** Update when the object is ready */
|
|
10
|
+
|
|
4
11
|
/**
|
|
5
|
-
* Update with the current `fetch`
|
|
12
|
+
* Update with the current `fetch` function and status of the object.
|
|
6
13
|
* - If both `fetch` and `error` are `null`, it is still loading the fetcher
|
|
7
14
|
* - If `fetch` is not `null`, the object is ready to be fetched
|
|
8
15
|
* - If `error` is not `null`, there was an error loading the object
|
|
9
16
|
*/
|
|
17
|
+
|
|
10
18
|
/** ObjectFetchManager for managing a subscription to an object using a VariableDescriptor */
|
|
19
|
+
|
|
11
20
|
/** Context for tracking an implementation of the ObjectFetchManager. */
|
|
12
21
|
export var ObjectFetchManagerContext = /*#__PURE__*/createContext(null);
|
|
13
22
|
|
|
@@ -19,34 +28,24 @@ export var ObjectFetchManagerContext = /*#__PURE__*/createContext(null);
|
|
|
19
28
|
* Retrying is left up to the ObjectManager implementation used from this context.
|
|
20
29
|
*/
|
|
21
30
|
export function useObjectFetch(descriptor) {
|
|
22
|
-
var [currentUpdate, setCurrentUpdate] = useState(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}));
|
|
26
|
-
var objectFetcher = useContext(ObjectFetcherContext);
|
|
31
|
+
var [currentUpdate, setCurrentUpdate] = useState({
|
|
32
|
+
status: 'loading'
|
|
33
|
+
});
|
|
27
34
|
var objectFetchManager = useContext(ObjectFetchManagerContext);
|
|
28
35
|
useEffect(() => {
|
|
29
36
|
if (objectFetchManager == null) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
});
|
|
35
|
-
} else {
|
|
36
|
-
setCurrentUpdate({
|
|
37
|
-
fetch: () => objectFetcher(descriptor),
|
|
38
|
-
error: null
|
|
39
|
-
});
|
|
40
|
-
}
|
|
37
|
+
setCurrentUpdate({
|
|
38
|
+
error: new Error('No ObjectFetchManager available in context'),
|
|
39
|
+
status: 'error'
|
|
40
|
+
});
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
|
-
//
|
|
44
|
-
setCurrentUpdate({
|
|
45
|
-
|
|
46
|
-
error: null
|
|
43
|
+
// Update to signal we're still loading, if we're not already in a loading state.
|
|
44
|
+
setCurrentUpdate(oldUpdate => oldUpdate.status === 'loading' ? oldUpdate : {
|
|
45
|
+
status: 'loading'
|
|
47
46
|
});
|
|
48
47
|
return objectFetchManager.subscribe(descriptor, setCurrentUpdate);
|
|
49
|
-
}, [descriptor,
|
|
48
|
+
}, [descriptor, objectFetchManager]);
|
|
50
49
|
return currentUpdate;
|
|
51
50
|
}
|
|
52
51
|
//# sourceMappingURL=useObjectFetch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useObjectFetch.js","names":["createContext","useContext","useEffect","useState","
|
|
1
|
+
{"version":3,"file":"useObjectFetch.js","names":["createContext","useContext","useEffect","useState","ObjectFetchManagerContext","useObjectFetch","descriptor","currentUpdate","setCurrentUpdate","status","objectFetchManager","error","Error","oldUpdate","subscribe"],"sources":["../src/useObjectFetch.ts"],"sourcesContent":["import { createContext, useContext, useEffect, useState } from 'react';\nimport type { dh } from '@deephaven/jsapi-types';\n\n/** Function for unsubscribing from a given subscription */\nexport type UnsubscribeFunction = () => void;\n\n/** Update when the ObjectFetch is still loading */\nexport type ObjectFetchLoading = {\n status: 'loading';\n};\n\n/** Update when the ObjectFetch has errored */\nexport type ObjectFetchError = {\n error: NonNullable<unknown>;\n status: 'error';\n};\n\n/** Update when the object is ready */\nexport type ObjectFetchReady<T> = {\n fetch: () => Promise<T>;\n status: 'ready';\n};\n\n/**\n * Update with the current `fetch` function and status of the object.\n * - If both `fetch` and `error` are `null`, it is still loading the fetcher\n * - If `fetch` is not `null`, the object is ready to be fetched\n * - If `error` is not `null`, there was an error loading the object\n */\nexport type ObjectFetchUpdate<T = unknown> =\n | ObjectFetchLoading\n | ObjectFetchError\n | ObjectFetchReady<T>;\n\nexport type ObjectFetchUpdateCallback<T = unknown> = (\n update: ObjectFetchUpdate<T>\n) => void;\n\n/** ObjectFetchManager for managing a subscription to an object using a VariableDescriptor */\nexport type ObjectFetchManager = {\n /**\n * Subscribe to the fetch function for an object using a variable descriptor.\n * It's possible that the fetch function changes over time, due to disconnection/reconnection, starting/stopping of applications that the object may be associated with, etc.\n *\n * @param descriptor Descriptor object of the object to fetch. Can be extended by a specific implementation to include more details necessary for the ObjectManager.\n * @param onUpdate Callback function to be called when the object is updated.\n * @returns An unsubscribe function to stop listening for fetch updates and clean up the object.\n */\n subscribe: <T = unknown>(\n descriptor: dh.ide.VariableDescriptor,\n onUpdate: ObjectFetchUpdateCallback<T>\n ) => UnsubscribeFunction;\n};\n\n/** Context for tracking an implementation of the ObjectFetchManager. */\nexport const ObjectFetchManagerContext =\n createContext<ObjectFetchManager | null>(null);\n\n/**\n * Retrieve a `fetch` function for the given variable descriptor.\n *\n * @param descriptor Descriptor to get the `fetch` function for\n * @returns An object with the current `fetch` function, OR an error status set if there was an issue fetching the object.\n * Retrying is left up to the ObjectManager implementation used from this context.\n */\nexport function useObjectFetch<T = unknown>(\n descriptor: dh.ide.VariableDescriptor\n): ObjectFetchUpdate<T> {\n const [currentUpdate, setCurrentUpdate] = useState<ObjectFetchUpdate<T>>({\n status: 'loading',\n });\n\n const objectFetchManager = useContext(ObjectFetchManagerContext);\n\n useEffect(() => {\n if (objectFetchManager == null) {\n setCurrentUpdate({\n error: new Error('No ObjectFetchManager available in context'),\n status: 'error',\n });\n return;\n }\n // Update to signal we're still loading, if we're not already in a loading state.\n setCurrentUpdate(oldUpdate =>\n oldUpdate.status === 'loading' ? oldUpdate : { status: 'loading' }\n );\n return objectFetchManager.subscribe(descriptor, setCurrentUpdate);\n }, [descriptor, objectFetchManager]);\n\n return currentUpdate;\n}\n"],"mappings":"AAAA,SAASA,aAAa,EAAEC,UAAU,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;;AAGtE;;AAGA;;AAKA;;AAMA;;AAMA;AACA;AACA;AACA;AACA;AACA;;AAUA;;AAgBA;AACA,OAAO,IAAMC,yBAAyB,gBACpCJ,aAAa,CAA4B,IAAI,CAAC;;AAEhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASK,cAAcA,CAC5BC,UAAqC,EACf;EACtB,IAAM,CAACC,aAAa,EAAEC,gBAAgB,CAAC,GAAGL,QAAQ,CAAuB;IACvEM,MAAM,EAAE;EACV,CAAC,CAAC;EAEF,IAAMC,kBAAkB,GAAGT,UAAU,CAACG,yBAAyB,CAAC;EAEhEF,SAAS,CAAC,MAAM;IACd,IAAIQ,kBAAkB,IAAI,IAAI,EAAE;MAC9BF,gBAAgB,CAAC;QACfG,KAAK,EAAE,IAAIC,KAAK,CAAC,4CAA4C,CAAC;QAC9DH,MAAM,EAAE;MACV,CAAC,CAAC;MACF;IACF;IACA;IACAD,gBAAgB,CAACK,SAAS,IACxBA,SAAS,CAACJ,MAAM,KAAK,SAAS,GAAGI,SAAS,GAAG;MAAEJ,MAAM,EAAE;IAAU,CACnE,CAAC;IACD,OAAOC,kBAAkB,CAACI,SAAS,CAACR,UAAU,EAAEE,gBAAgB,CAAC;EACnE,CAAC,EAAE,CAACF,UAAU,EAAEI,kBAAkB,CAAC,CAAC;EAEpC,OAAOH,aAAa;AACtB"}
|
package/dist/useWidget.d.ts
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import { dh } from '@deephaven/jsapi-types';
|
|
1
|
+
import type { dh } from '@deephaven/jsapi-types';
|
|
2
|
+
/**
|
|
3
|
+
* Types of widgets that can be fetched with this hook.
|
|
4
|
+
*/
|
|
5
|
+
type WidgetTypes = dh.Table | dh.TreeTable | dh.PartitionedTable | dh.plot.Figure | dh.Widget;
|
|
2
6
|
/**
|
|
3
7
|
* Wrapper object for a widget and error status. Both widget and error will be `null` if it is still loading.
|
|
4
8
|
*/
|
|
5
|
-
type WidgetWrapper<T extends
|
|
9
|
+
type WidgetWrapper<T extends WidgetTypes = dh.Widget> = {
|
|
6
10
|
/** Widget object to retrieve */
|
|
7
11
|
widget: T | null;
|
|
8
12
|
/** Error status if there was an issue fetching the widget */
|
|
9
|
-
error: unknown | null;
|
|
13
|
+
error: NonNullable<unknown> | null;
|
|
10
14
|
};
|
|
11
15
|
/**
|
|
12
16
|
* Retrieve a widget for the given variable descriptor. Note that if the widget is successfully fetched, ownership of the widget is passed to the consumer and will need to close the object as well.
|
|
13
|
-
* @param descriptor Descriptor to get the widget for
|
|
17
|
+
* @param descriptor Descriptor to get the widget for. Should be stable to avoid infinite re-fetching.
|
|
14
18
|
* @returns A WidgetWrapper object that contains the widget or an error status if there was an issue fetching the widget. Will contain nulls if still loading.
|
|
15
19
|
*/
|
|
16
|
-
export declare function useWidget<T extends
|
|
20
|
+
export declare function useWidget<T extends WidgetTypes = dh.Widget>(descriptor: dh.ide.VariableDescriptor): WidgetWrapper<T>;
|
|
17
21
|
export default useWidget;
|
|
18
22
|
//# sourceMappingURL=useWidget.d.ts.map
|
package/dist/useWidget.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWidget.d.ts","sourceRoot":"","sources":["../src/useWidget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"useWidget.d.ts","sourceRoot":"","sources":["../src/useWidget.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;AAQjD;;GAEG;AACH,KAAK,WAAW,GACZ,EAAE,CAAC,KAAK,GACR,EAAE,CAAC,SAAS,GACZ,EAAE,CAAC,gBAAgB,GACnB,EAAE,CAAC,IAAI,CAAC,MAAM,GACd,EAAE,CAAC,MAAM,CAAC;AAEd;;GAEG;AACH,KAAK,aAAa,CAAC,CAAC,SAAS,WAAW,GAAG,EAAE,CAAC,MAAM,IAAI;IACtD,gCAAgC;IAChC,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC;IAEjB,6DAA6D;IAC7D,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;CACpC,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,WAAW,GAAG,EAAE,CAAC,MAAM,EACzD,UAAU,EAAE,EAAE,CAAC,GAAG,CAAC,kBAAkB,GACpC,aAAa,CAAC,CAAC,CAAC,CAgElB;AAED,eAAe,SAAS,CAAC"}
|
package/dist/useWidget.js
CHANGED
|
@@ -6,13 +6,17 @@ import { useEffect, useState } from 'react';
|
|
|
6
6
|
import { useObjectFetch } from "./useObjectFetch.js";
|
|
7
7
|
var log = Log.module('useWidget');
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Types of widgets that can be fetched with this hook.
|
|
11
|
+
*/
|
|
12
|
+
|
|
9
13
|
/**
|
|
10
14
|
* Wrapper object for a widget and error status. Both widget and error will be `null` if it is still loading.
|
|
11
15
|
*/
|
|
12
16
|
|
|
13
17
|
/**
|
|
14
18
|
* Retrieve a widget for the given variable descriptor. Note that if the widget is successfully fetched, ownership of the widget is passed to the consumer and will need to close the object as well.
|
|
15
|
-
* @param descriptor Descriptor to get the widget for
|
|
19
|
+
* @param descriptor Descriptor to get the widget for. Should be stable to avoid infinite re-fetching.
|
|
16
20
|
* @returns A WidgetWrapper object that contains the widget or an error status if there was an issue fetching the widget. Will contain nulls if still loading.
|
|
17
21
|
*/
|
|
18
22
|
export function useWidget(descriptor) {
|
|
@@ -24,18 +28,17 @@ export function useWidget(descriptor) {
|
|
|
24
28
|
useEffect(function loadWidget() {
|
|
25
29
|
log.debug('loadWidget', descriptor);
|
|
26
30
|
var {
|
|
27
|
-
|
|
28
|
-
error
|
|
31
|
+
status
|
|
29
32
|
} = objectFetch;
|
|
30
|
-
if (
|
|
33
|
+
if (status === 'error') {
|
|
31
34
|
// We can't fetch if there's an error getting the fetcher, just return an error
|
|
32
35
|
setWrapper({
|
|
33
36
|
widget: null,
|
|
34
|
-
error
|
|
37
|
+
error: objectFetch.error
|
|
35
38
|
});
|
|
36
39
|
return;
|
|
37
40
|
}
|
|
38
|
-
if (
|
|
41
|
+
if (status === 'loading') {
|
|
39
42
|
// Still loading
|
|
40
43
|
setWrapper({
|
|
41
44
|
widget: null,
|
|
@@ -43,7 +46,9 @@ export function useWidget(descriptor) {
|
|
|
43
46
|
});
|
|
44
47
|
return;
|
|
45
48
|
}
|
|
46
|
-
|
|
49
|
+
var {
|
|
50
|
+
fetch
|
|
51
|
+
} = objectFetch;
|
|
47
52
|
// We should be able to load the widget. Load it asynchronously, and set the widget when it's done.
|
|
48
53
|
// If we get cancelled before the fetch is done, we should close the widget and its exported objects.
|
|
49
54
|
// If not though, the consumer of the widget is expected to take ownership and close the widget appropriately.
|
|
@@ -59,9 +64,11 @@ export function useWidget(descriptor) {
|
|
|
59
64
|
if (isCancelled) {
|
|
60
65
|
log.debug2('loadWidgetInternal cancelled', descriptor, newWidget);
|
|
61
66
|
newWidget.close();
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
if ('exportedObjects' in newWidget) {
|
|
68
|
+
newWidget.exportedObjects.forEach(exportedObject => {
|
|
69
|
+
exportedObject.close();
|
|
70
|
+
});
|
|
71
|
+
}
|
|
65
72
|
return;
|
|
66
73
|
}
|
|
67
74
|
log.debug('loadWidgetInternal done', descriptor, newWidget);
|
|
@@ -76,7 +83,7 @@ export function useWidget(descriptor) {
|
|
|
76
83
|
log.error('loadWidgetInternal error', descriptor, e);
|
|
77
84
|
setWrapper({
|
|
78
85
|
widget: null,
|
|
79
|
-
error: e
|
|
86
|
+
error: e !== null && e !== void 0 ? e : new Error('Null error')
|
|
80
87
|
});
|
|
81
88
|
}
|
|
82
89
|
});
|
package/dist/useWidget.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWidget.js","names":["Log","assertNotNull","useEffect","useState","useObjectFetch","log","module","useWidget","descriptor","wrapper","setWrapper","widget","error","objectFetch","loadWidget","debug","fetch","isCancelled","loadWidgetInternal","_loadWidgetInternal","apply","arguments","_asyncToGenerator","newWidget","debug2","close","exportedObjects","forEach","exportedObject","e"],"sources":["../src/useWidget.ts"],"sourcesContent":["import { dh } from '@deephaven/jsapi-types';\nimport Log from '@deephaven/log';\nimport { assertNotNull } from '@deephaven/utils';\nimport { useEffect, useState } from 'react';\nimport { useObjectFetch } from './useObjectFetch';\n\nconst log = Log.module('useWidget');\n\n/**\n * Wrapper object for a widget and error status. Both widget and error will be `null` if it is still loading.\n */\ntype WidgetWrapper<T extends
|
|
1
|
+
{"version":3,"file":"useWidget.js","names":["Log","assertNotNull","useEffect","useState","useObjectFetch","log","module","useWidget","descriptor","wrapper","setWrapper","widget","error","objectFetch","loadWidget","debug","status","fetch","isCancelled","loadWidgetInternal","_loadWidgetInternal","apply","arguments","_asyncToGenerator","newWidget","debug2","close","exportedObjects","forEach","exportedObject","e","Error"],"sources":["../src/useWidget.ts"],"sourcesContent":["import type { dh } from '@deephaven/jsapi-types';\nimport Log from '@deephaven/log';\nimport { assertNotNull } from '@deephaven/utils';\nimport { useEffect, useState } from 'react';\nimport { useObjectFetch } from './useObjectFetch';\n\nconst log = Log.module('useWidget');\n\n/**\n * Types of widgets that can be fetched with this hook.\n */\ntype WidgetTypes =\n | dh.Table\n | dh.TreeTable\n | dh.PartitionedTable\n | dh.plot.Figure\n | dh.Widget;\n\n/**\n * Wrapper object for a widget and error status. Both widget and error will be `null` if it is still loading.\n */\ntype WidgetWrapper<T extends WidgetTypes = dh.Widget> = {\n /** Widget object to retrieve */\n widget: T | null;\n\n /** Error status if there was an issue fetching the widget */\n error: NonNullable<unknown> | null;\n};\n\n/**\n * Retrieve a widget for the given variable descriptor. Note that if the widget is successfully fetched, ownership of the widget is passed to the consumer and will need to close the object as well.\n * @param descriptor Descriptor to get the widget for. Should be stable to avoid infinite re-fetching.\n * @returns A WidgetWrapper object that contains the widget or an error status if there was an issue fetching the widget. Will contain nulls if still loading.\n */\nexport function useWidget<T extends WidgetTypes = dh.Widget>(\n descriptor: dh.ide.VariableDescriptor\n): WidgetWrapper<T> {\n const [wrapper, setWrapper] = useState<WidgetWrapper<T>>(() => ({\n widget: null,\n error: null,\n }));\n const objectFetch = useObjectFetch<T>(descriptor);\n\n useEffect(\n function loadWidget() {\n log.debug('loadWidget', descriptor);\n\n const { status } = objectFetch;\n\n if (status === 'error') {\n // We can't fetch if there's an error getting the fetcher, just return an error\n setWrapper({ widget: null, error: objectFetch.error });\n return;\n }\n\n if (status === 'loading') {\n // Still loading\n setWrapper({ widget: null, error: null });\n return;\n }\n\n const { fetch } = objectFetch;\n // We should be able to load the widget. Load it asynchronously, and set the widget when it's done.\n // If we get cancelled before the fetch is done, we should close the widget and its exported objects.\n // If not though, the consumer of the widget is expected to take ownership and close the widget appropriately.\n let isCancelled = false;\n async function loadWidgetInternal() {\n try {\n assertNotNull(fetch);\n const newWidget = await fetch();\n if (isCancelled) {\n log.debug2('loadWidgetInternal cancelled', descriptor, newWidget);\n newWidget.close();\n if ('exportedObjects' in newWidget) {\n newWidget.exportedObjects.forEach(exportedObject => {\n exportedObject.close();\n });\n }\n return;\n }\n log.debug('loadWidgetInternal done', descriptor, newWidget);\n\n setWrapper({ widget: newWidget, error: null });\n } catch (e) {\n if (isCancelled) {\n return;\n }\n log.error('loadWidgetInternal error', descriptor, e);\n setWrapper({ widget: null, error: e ?? new Error('Null error') });\n }\n }\n loadWidgetInternal();\n return () => {\n isCancelled = true;\n };\n },\n [descriptor, objectFetch]\n );\n\n return wrapper;\n}\n\nexport default useWidget;\n"],"mappings":";;AACA,OAAOA,GAAG,MAAM,gBAAgB;AAChC,SAASC,aAAa,QAAQ,kBAAkB;AAChD,SAASC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAAC,SACnCC,cAAc;AAEvB,IAAMC,GAAG,GAAGL,GA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iBAAiB,IAAIF,SAAS,EAAE;cAClCA,SAAS,CAACG,eAAe,CAACC,OAAO,CAACC,cAAc,IAAI;gBAClDA,cAAc,CAACH,KAAK,CAAC,CAAC;cACxB,CAAC,CAAC;YACJ;YACA;UACF;UACArB,GAAG,CAACU,KAAK,CAAC,yBAAyB,EAAEP,UAAU,EAAEgB,SAAS,CAAC;UAE3Dd,UAAU,CAAC;YAAEC,MAAM,EAAEa,SAAS;YAAEZ,KAAK,EAAE;UAAK,CAAC,CAAC;QAChD,CAAC,CAAC,OAAOkB,CAAC,EAAE;UACV,IAAIZ,WAAW,EAAE;YACf;UACF;UACAb,GAAG,CAACO,KAAK,CAAC,0BAA0B,EAAEJ,UAAU,EAAEsB,CAAC,CAAC;UACpDpB,UAAU,CAAC;YAAEC,MAAM,EAAE,IAAI;YAAEC,KAAK,EAAEkB,CAAC,aAADA,CAAC,cAADA,CAAC,GAAI,IAAIC,KAAK,CAAC,YAAY;UAAE,CAAC,CAAC;QACnE;MACF,CAAC;MAAA,OAAAX,mBAAA,CAAAC,KAAA,OAAAC,SAAA;IAAA;IACDH,kBAAkB,CAAC,CAAC;IACpB,OAAO,MAAM;MACXD,WAAW,GAAG,IAAI;IACpB,CAAC;EACH,CAAC,EACD,CAACV,UAAU,EAAEK,WAAW,CAC1B,CAAC;EAED,OAAOJ,OAAO;AAChB;AAEA,eAAeF,SAAS"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deephaven/jsapi-bootstrap",
|
|
3
|
-
"version": "0.78.
|
|
3
|
+
"version": "0.78.3",
|
|
4
4
|
"description": "Deephaven JSAPI Bootstrap",
|
|
5
5
|
"author": "Deephaven Data Labs LLC",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"build:sass": "sass --embed-sources --load-path=../../node_modules ./src:./dist"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@deephaven/components": "^0.78.
|
|
26
|
-
"@deephaven/jsapi-types": "1.0.0-dev0.
|
|
27
|
-
"@deephaven/log": "^0.78.
|
|
28
|
-
"@deephaven/react-hooks": "^0.78.
|
|
29
|
-
"@deephaven/utils": "^0.78.
|
|
25
|
+
"@deephaven/components": "^0.78.0",
|
|
26
|
+
"@deephaven/jsapi-types": "^1.0.0-dev0.33.4",
|
|
27
|
+
"@deephaven/log": "^0.78.0",
|
|
28
|
+
"@deephaven/react-hooks": "^0.78.0",
|
|
29
|
+
"@deephaven/utils": "^0.78.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"react": "^17.x"
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "5236ccef254e2bd2af99823ab66a4cce51762e9b"
|
|
45
45
|
}
|