@deephaven/jsapi-bootstrap 0.78.1-use-widget.2 → 0.79.0
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/index.d.ts +0 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/package.json +5 -6
- package/dist/useObjectFetch.d.ts +0 -43
- package/dist/useObjectFetch.d.ts.map +0 -1
- package/dist/useObjectFetch.js +0 -52
- package/dist/useObjectFetch.js.map +0 -1
- package/dist/useWidget.d.ts +0 -18
- package/dist/useWidget.d.ts.map +0 -1
- package/dist/useWidget.js +0 -89
- package/dist/useWidget.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,5 @@ export * from './DeferredApiBootstrap';
|
|
|
4
4
|
export * from './useApi';
|
|
5
5
|
export * from './useClient';
|
|
6
6
|
export * from './useDeferredApi';
|
|
7
|
-
export * from './useObjectFetch';
|
|
8
7
|
export * from './useObjectFetcher';
|
|
9
|
-
export * from './useWidget';
|
|
10
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,5 @@ export * from "./DeferredApiBootstrap.js";
|
|
|
4
4
|
export * from "./useApi.js";
|
|
5
5
|
export * from "./useClient.js";
|
|
6
6
|
export * from "./useDeferredApi.js";
|
|
7
|
-
export * from "./useObjectFetch.js";
|
|
8
7
|
export * from "./useObjectFetcher.js";
|
|
9
|
-
export * from "./useWidget.js";
|
|
10
8
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export * from './ApiBootstrap';\nexport * from './ClientBootstrap';\nexport * from './DeferredApiBootstrap';\nexport * from './useApi';\nexport * from './useClient';\nexport * from './useDeferredApi';\nexport * from './
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export * from './ApiBootstrap';\nexport * from './ClientBootstrap';\nexport * from './DeferredApiBootstrap';\nexport * from './useApi';\nexport * from './useClient';\nexport * from './useDeferredApi';\nexport * from './useObjectFetcher';\n"],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deephaven/jsapi-bootstrap",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.79.0",
|
|
4
4
|
"description": "Deephaven JSAPI Bootstrap",
|
|
5
5
|
"author": "Deephaven Data Labs LLC",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -22,11 +22,10 @@
|
|
|
22
22
|
"build:sass": "sass --embed-sources --load-path=../../node_modules ./src:./dist"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@deephaven/components": "^0.
|
|
25
|
+
"@deephaven/components": "^0.79.0",
|
|
26
26
|
"@deephaven/jsapi-types": "1.0.0-dev0.34.0",
|
|
27
|
-
"@deephaven/log": "^0.
|
|
28
|
-
"@deephaven/react-hooks": "^0.
|
|
29
|
-
"@deephaven/utils": "^0.78.1-use-widget.2+a7aa1041"
|
|
27
|
+
"@deephaven/log": "^0.79.0",
|
|
28
|
+
"@deephaven/react-hooks": "^0.79.0"
|
|
30
29
|
},
|
|
31
30
|
"devDependencies": {
|
|
32
31
|
"react": "^17.x"
|
|
@@ -41,5 +40,5 @@
|
|
|
41
40
|
"publishConfig": {
|
|
42
41
|
"access": "public"
|
|
43
42
|
},
|
|
44
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "95ec12ba29b3866c27a87d35252b073281f403af"
|
|
45
44
|
}
|
package/dist/useObjectFetch.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import type { dh } from '@deephaven/jsapi-types';
|
|
3
|
-
/** Function for unsubscribing from a given subscription */
|
|
4
|
-
export type UnsubscribeFunction = () => void;
|
|
5
|
-
/**
|
|
6
|
-
* Update with the current `fetch` fuonction and status of the object.
|
|
7
|
-
* - If both `fetch` and `error` are `null`, it is still loading the fetcher
|
|
8
|
-
* - If `fetch` is not `null`, the object is ready to be fetched
|
|
9
|
-
* - If `error` is not `null`, there was an error loading the object
|
|
10
|
-
*/
|
|
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
|
-
};
|
|
22
|
-
export type ObjectFetchUpdateCallback<T = unknown> = (update: ObjectFetchUpdate<T>) => void;
|
|
23
|
-
/** ObjectFetchManager for managing a subscription to an object using a VariableDescriptor */
|
|
24
|
-
export type ObjectFetchManager = {
|
|
25
|
-
/**
|
|
26
|
-
*
|
|
27
|
-
* @param descriptor Descriptor object to fetch the object from. Can be extended by a specific implementation to include more details necessary for the ObjectManager.
|
|
28
|
-
* @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.
|
|
30
|
-
*/
|
|
31
|
-
subscribe: <T = unknown>(descriptor: dh.ide.VariableDescriptor, onUpdate: ObjectFetchUpdateCallback<T>) => UnsubscribeFunction;
|
|
32
|
-
};
|
|
33
|
-
/** Context for tracking an implementation of the ObjectFetchManager. */
|
|
34
|
-
export declare const ObjectFetchManagerContext: import("react").Context<ObjectFetchManager | null>;
|
|
35
|
-
/**
|
|
36
|
-
* Retrieve a `fetch` function for the given variable descriptor.
|
|
37
|
-
*
|
|
38
|
-
* @param descriptor Descriptor to get the `fetch` function for
|
|
39
|
-
* @returns An object with the current `fetch` function, OR an error status set if there was an issue fetching the object.
|
|
40
|
-
* Retrying is left up to the ObjectManager implementation used from this context.
|
|
41
|
-
*/
|
|
42
|
-
export declare function useObjectFetch<T = unknown>(descriptor: dh.ide.VariableDescriptor): ObjectFetchUpdate<T>;
|
|
43
|
-
//# sourceMappingURL=useObjectFetch.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useObjectFetch.d.ts","sourceRoot":"","sources":["../src/useObjectFetch.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;AAGjD,2DAA2D;AAC3D,MAAM,MAAM,mBAAmB,GAAG,MAAM,IAAI,CAAC;AAE7C;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,GAAG,OAAO,IAAI;IAC3C;;OAEG;IACH,KAAK,EAAE,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAEjC;;;OAGG;IACH,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,yBAAyB,CAAC,CAAC,GAAG,OAAO,IAAI,CACnD,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC,KACzB,IAAI,CAAC;AAEV,6FAA6F;AAC7F,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;;;OAKG;IACH,SAAS,EAAE,CAAC,CAAC,GAAG,OAAO,EACrB,UAAU,EAAE,EAAE,CAAC,GAAG,CAAC,kBAAkB,EACrC,QAAQ,EAAE,yBAAyB,CAAC,CAAC,CAAC,KACnC,mBAAmB,CAAC;CAC1B,CAAC;AAEF,wEAAwE;AACxE,eAAO,MAAM,yBAAyB,oDACU,CAAC;AAEjD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,CAAC,GAAG,OAAO,EACxC,UAAU,EAAE,EAAE,CAAC,GAAG,CAAC,kBAAkB,GACpC,iBAAiB,CAAC,CAAC,CAAC,CAmCtB"}
|
package/dist/useObjectFetch.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { createContext, useContext, useEffect, useState } from 'react';
|
|
2
|
-
import { ObjectFetcherContext } from "./useObjectFetcher.js";
|
|
3
|
-
/** Function for unsubscribing from a given subscription */
|
|
4
|
-
/**
|
|
5
|
-
* Update with the current `fetch` fuonction and status of the object.
|
|
6
|
-
* - If both `fetch` and `error` are `null`, it is still loading the fetcher
|
|
7
|
-
* - If `fetch` is not `null`, the object is ready to be fetched
|
|
8
|
-
* - If `error` is not `null`, there was an error loading the object
|
|
9
|
-
*/
|
|
10
|
-
/** ObjectFetchManager for managing a subscription to an object using a VariableDescriptor */
|
|
11
|
-
/** Context for tracking an implementation of the ObjectFetchManager. */
|
|
12
|
-
export var ObjectFetchManagerContext = /*#__PURE__*/createContext(null);
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Retrieve a `fetch` function for the given variable descriptor.
|
|
16
|
-
*
|
|
17
|
-
* @param descriptor Descriptor to get the `fetch` function for
|
|
18
|
-
* @returns An object with the current `fetch` function, OR an error status set if there was an issue fetching the object.
|
|
19
|
-
* Retrying is left up to the ObjectManager implementation used from this context.
|
|
20
|
-
*/
|
|
21
|
-
export function useObjectFetch(descriptor) {
|
|
22
|
-
var [currentUpdate, setCurrentUpdate] = useState(() => ({
|
|
23
|
-
fetch: null,
|
|
24
|
-
error: null
|
|
25
|
-
}));
|
|
26
|
-
var objectFetcher = useContext(ObjectFetcherContext);
|
|
27
|
-
var objectFetchManager = useContext(ObjectFetchManagerContext);
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
if (objectFetchManager == null) {
|
|
30
|
-
if (objectFetcher == null) {
|
|
31
|
-
setCurrentUpdate({
|
|
32
|
-
fetch: null,
|
|
33
|
-
error: new Error('No ObjectFetchManager available in context')
|
|
34
|
-
});
|
|
35
|
-
} else {
|
|
36
|
-
setCurrentUpdate({
|
|
37
|
-
fetch: () => objectFetcher(descriptor),
|
|
38
|
-
error: null
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
// Signal that we're still loading
|
|
44
|
-
setCurrentUpdate({
|
|
45
|
-
fetch: null,
|
|
46
|
-
error: null
|
|
47
|
-
});
|
|
48
|
-
return objectFetchManager.subscribe(descriptor, setCurrentUpdate);
|
|
49
|
-
}, [descriptor, objectFetcher, objectFetchManager]);
|
|
50
|
-
return currentUpdate;
|
|
51
|
-
}
|
|
52
|
-
//# sourceMappingURL=useObjectFetch.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useObjectFetch.js","names":["createContext","useContext","useEffect","useState","ObjectFetcherContext","ObjectFetchManagerContext","useObjectFetch","descriptor","currentUpdate","setCurrentUpdate","fetch","error","objectFetcher","objectFetchManager","Error","subscribe"],"sources":["../src/useObjectFetch.ts"],"sourcesContent":["import { createContext, useContext, useEffect, useState } from 'react';\nimport type { dh } from '@deephaven/jsapi-types';\nimport { ObjectFetcherContext } from './useObjectFetcher';\n\n/** Function for unsubscribing from a given subscription */\nexport type UnsubscribeFunction = () => void;\n\n/**\n * Update with the current `fetch` fuonction 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 /**\n * Function to fetch the object. If `null`, the object is still loading or there was an error.\n */\n fetch: (() => Promise<T>) | null;\n\n /**\n * Error that occurred while fetching the object. If `null`, there was no error.\n * Will automatically retry when possible while the subscribed.\n */\n error: unknown | null;\n};\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 *\n * @param descriptor Descriptor object to fetch the object from. 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 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 () => ({\n fetch: null,\n error: null,\n })\n );\n\n const objectFetcher = useContext(ObjectFetcherContext);\n const objectFetchManager = useContext(ObjectFetchManagerContext);\n\n useEffect(() => {\n if (objectFetchManager == null) {\n if (objectFetcher == null) {\n setCurrentUpdate({\n fetch: null,\n error: new Error('No ObjectFetchManager available in context'),\n });\n } else {\n setCurrentUpdate({\n fetch: () => objectFetcher(descriptor),\n error: null,\n });\n }\n return;\n }\n // Signal that we're still loading\n setCurrentUpdate({\n fetch: null,\n error: null,\n });\n return objectFetchManager.subscribe(descriptor, setCurrentUpdate);\n }, [descriptor, objectFetcher, objectFetchManager]);\n\n return currentUpdate;\n}\n"],"mappings":"AAAA,SAASA,aAAa,EAAEC,UAAU,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAAC,SAE9DC,oBAAoB;AAE7B;AAGA;AACA;AACA;AACA;AACA;AACA;AAkBA;AAcA;AACA,OAAO,IAAMC,yBAAyB,gBACpCL,aAAa,CAA4B,IAAI,CAAC;;AAEhD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASM,cAAcA,CAC5BC,UAAqC,EACf;EACtB,IAAM,CAACC,aAAa,EAAEC,gBAAgB,CAAC,GAAGN,QAAQ,CAChD,OAAO;IACLO,KAAK,EAAE,IAAI;IACXC,KAAK,EAAE;EACT,CAAC,CACH,CAAC;EAED,IAAMC,aAAa,GAAGX,UAAU,CAACG,oBAAoB,CAAC;EACtD,IAAMS,kBAAkB,GAAGZ,UAAU,CAACI,yBAAyB,CAAC;EAEhEH,SAAS,CAAC,MAAM;IACd,IAAIW,kBAAkB,IAAI,IAAI,EAAE;MAC9B,IAAID,aAAa,IAAI,IAAI,EAAE;QACzBH,gBAAgB,CAAC;UACfC,KAAK,EAAE,IAAI;UACXC,KAAK,EAAE,IAAIG,KAAK,CAAC,4CAA4C;QAC/D,CAAC,CAAC;MACJ,CAAC,MAAM;QACLL,gBAAgB,CAAC;UACfC,KAAK,EAAEA,CAAA,KAAME,aAAa,CAACL,UAAU,CAAC;UACtCI,KAAK,EAAE;QACT,CAAC,CAAC;MACJ;MACA;IACF;IACA;IACAF,gBAAgB,CAAC;MACfC,KAAK,EAAE,IAAI;MACXC,KAAK,EAAE;IACT,CAAC,CAAC;IACF,OAAOE,kBAAkB,CAACE,SAAS,CAACR,UAAU,EAAEE,gBAAgB,CAAC;EACnE,CAAC,EAAE,CAACF,UAAU,EAAEK,aAAa,EAAEC,kBAAkB,CAAC,CAAC;EAEnD,OAAOL,aAAa;AACtB"}
|
package/dist/useWidget.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { dh } from '@deephaven/jsapi-types';
|
|
2
|
-
/**
|
|
3
|
-
* Wrapper object for a widget and error status. Both widget and error will be `null` if it is still loading.
|
|
4
|
-
*/
|
|
5
|
-
type WidgetWrapper<T extends dh.Widget = dh.Widget> = {
|
|
6
|
-
/** Widget object to retrieve */
|
|
7
|
-
widget: T | null;
|
|
8
|
-
/** Error status if there was an issue fetching the widget */
|
|
9
|
-
error: unknown | null;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* 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
|
|
14
|
-
* @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
|
-
*/
|
|
16
|
-
export declare function useWidget<T extends dh.Widget = dh.Widget>(descriptor: dh.ide.VariableDescriptor): WidgetWrapper<T>;
|
|
17
|
-
export default useWidget;
|
|
18
|
-
//# sourceMappingURL=useWidget.d.ts.map
|
package/dist/useWidget.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useWidget.d.ts","sourceRoot":"","sources":["../src/useWidget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;AAQ5C;;GAEG;AACH,KAAK,aAAa,CAAC,CAAC,SAAS,EAAE,CAAC,MAAM,GAAG,EAAE,CAAC,MAAM,IAAI;IACpD,gCAAgC;IAChC,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC;IAEjB,6DAA6D;IAC7D,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;CACvB,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,EAAE,CAAC,MAAM,GAAG,EAAE,CAAC,MAAM,EACvD,UAAU,EAAE,EAAE,CAAC,GAAG,CAAC,kBAAkB,GACpC,aAAa,CAAC,CAAC,CAAC,CA6DlB;AAED,eAAe,SAAS,CAAC"}
|
package/dist/useWidget.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
2
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
3
|
-
import Log from '@deephaven/log';
|
|
4
|
-
import { assertNotNull } from '@deephaven/utils';
|
|
5
|
-
import { useEffect, useState } from 'react';
|
|
6
|
-
import { useObjectFetch } from "./useObjectFetch.js";
|
|
7
|
-
var log = Log.module('useWidget');
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Wrapper object for a widget and error status. Both widget and error will be `null` if it is still loading.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* 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
|
|
16
|
-
* @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
|
-
*/
|
|
18
|
-
export function useWidget(descriptor) {
|
|
19
|
-
var [wrapper, setWrapper] = useState(() => ({
|
|
20
|
-
widget: null,
|
|
21
|
-
error: null
|
|
22
|
-
}));
|
|
23
|
-
var objectFetch = useObjectFetch(descriptor);
|
|
24
|
-
useEffect(function loadWidget() {
|
|
25
|
-
log.debug('loadWidget', descriptor);
|
|
26
|
-
var {
|
|
27
|
-
fetch,
|
|
28
|
-
error
|
|
29
|
-
} = objectFetch;
|
|
30
|
-
if (error != null) {
|
|
31
|
-
// We can't fetch if there's an error getting the fetcher, just return an error
|
|
32
|
-
setWrapper({
|
|
33
|
-
widget: null,
|
|
34
|
-
error
|
|
35
|
-
});
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
if (fetch == null) {
|
|
39
|
-
// Still loading
|
|
40
|
-
setWrapper({
|
|
41
|
-
widget: null,
|
|
42
|
-
error: null
|
|
43
|
-
});
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
var isCancelled = false;
|
|
47
|
-
function loadWidgetInternal() {
|
|
48
|
-
return _loadWidgetInternal.apply(this, arguments);
|
|
49
|
-
}
|
|
50
|
-
function _loadWidgetInternal() {
|
|
51
|
-
_loadWidgetInternal = _asyncToGenerator(function* () {
|
|
52
|
-
try {
|
|
53
|
-
assertNotNull(fetch);
|
|
54
|
-
var newWidget = yield fetch();
|
|
55
|
-
if (isCancelled) {
|
|
56
|
-
log.debug2('loadWidgetInternal cancelled', descriptor, newWidget);
|
|
57
|
-
newWidget.close();
|
|
58
|
-
newWidget.exportedObjects.forEach(exportedObject => {
|
|
59
|
-
exportedObject.close();
|
|
60
|
-
});
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
log.debug('loadWidgetInternal done', descriptor, newWidget);
|
|
64
|
-
setWrapper({
|
|
65
|
-
widget: newWidget,
|
|
66
|
-
error: null
|
|
67
|
-
});
|
|
68
|
-
} catch (e) {
|
|
69
|
-
if (isCancelled) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
log.error('loadWidgetInternal error', descriptor, e);
|
|
73
|
-
setWrapper({
|
|
74
|
-
widget: null,
|
|
75
|
-
error: e
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
return _loadWidgetInternal.apply(this, arguments);
|
|
80
|
-
}
|
|
81
|
-
loadWidgetInternal();
|
|
82
|
-
return () => {
|
|
83
|
-
isCancelled = true;
|
|
84
|
-
};
|
|
85
|
-
}, [descriptor, objectFetch]);
|
|
86
|
-
return wrapper;
|
|
87
|
-
}
|
|
88
|
-
export default useWidget;
|
|
89
|
-
//# sourceMappingURL=useWidget.js.map
|
package/dist/useWidget.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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 dh.Widget = 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: 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\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 dh.Widget = 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\n const objectFetch = useObjectFetch<T>(descriptor);\n\n useEffect(\n function loadWidget() {\n log.debug('loadWidget', descriptor);\n\n const { fetch, error } = objectFetch;\n\n if (error != null) {\n // We can't fetch if there's an error getting the fetcher, just return an error\n setWrapper({ widget: null, error });\n return;\n }\n\n if (fetch == null) {\n // Still loading\n setWrapper({ widget: null, error: null });\n return;\n }\n\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 newWidget.exportedObjects.forEach(\n (exportedObject: dh.WidgetExportedObject) => {\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 });\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,GAAG,CAACM,MAAM,CAAC,WAAW,CAAC;;AAEnC;AACA;AACA;;AASA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,SAASA,CACvBC,UAAqC,EACnB;EAClB,IAAM,CAACC,OAAO,EAAEC,UAAU,CAAC,GAAGP,QAAQ,CAAmB,OAAO;IAC9DQ,MAAM,EAAE,IAAI;IACZC,KAAK,EAAE;EACT,CAAC,CAAC,CAAC;EAEH,IAAMC,WAAW,GAAGT,cAAc,CAAII,UAAU,CAAC;EAEjDN,SAAS,CACP,SAASY,UAAUA,CAAA,EAAG;IACpBT,GAAG,CAACU,KAAK,CAAC,YAAY,EAAEP,UAAU,CAAC;IAEnC,IAAM;MAAEQ,KAAK;MAAEJ;IAAM,CAAC,GAAGC,WAAW;IAEpC,IAAID,KAAK,IAAI,IAAI,EAAE;MACjB;MACAF,UAAU,CAAC;QAAEC,MAAM,EAAE,IAAI;QAAEC;MAAM,CAAC,CAAC;MACnC;IACF;IAEA,IAAII,KAAK,IAAI,IAAI,EAAE;MACjB;MACAN,UAAU,CAAC;QAAEC,MAAM,EAAE,IAAI;QAAEC,KAAK,EAAE;MAAK,CAAC,CAAC;MACzC;IACF;IAEA,IAAIK,WAAW,GAAG,KAAK;IAAC,SACTC,kBAAkBA,CAAA;MAAA,OAAAC,mBAAA,CAAAC,KAAA,OAAAC,SAAA;IAAA;IAAA,SAAAF,oBAAA;MAAAA,mBAAA,GAAAG,iBAAA,CAAjC,aAAoC;QAClC,IAAI;UACFrB,aAAa,CAACe,KAAK,CAAC;UACpB,IAAMO,SAAS,SAASP,KAAK,CAAC,CAAC;UAC/B,IAAIC,WAAW,EAAE;YACfZ,GAAG,CAACmB,MAAM,CAAC,8BAA8B,EAAEhB,UAAU,EAAEe,SAAS,CAAC;YACjEA,SAAS,CAACE,KAAK,CAAC,CAAC;YACjBF,SAAS,CAACG,eAAe,CAACC,OAAO,CAC9BC,cAAuC,IAAK;cAC3CA,cAAc,CAACH,KAAK,CAAC,CAAC;YACxB,CACF,CAAC;YACD;UACF;UACApB,GAAG,CAACU,KAAK,CAAC,yBAAyB,EAAEP,UAAU,EAAEe,SAAS,CAAC;UAE3Db,UAAU,CAAC;YAAEC,MAAM,EAAEY,SAAS;YAAEX,KAAK,EAAE;UAAK,CAAC,CAAC;QAChD,CAAC,CAAC,OAAOiB,CAAC,EAAE;UACV,IAAIZ,WAAW,EAAE;YACf;UACF;UACAZ,GAAG,CAACO,KAAK,CAAC,0BAA0B,EAAEJ,UAAU,EAAEqB,CAAC,CAAC;UACpDnB,UAAU,CAAC;YAAEC,MAAM,EAAE,IAAI;YAAEC,KAAK,EAAEiB;UAAE,CAAC,CAAC;QACxC;MACF,CAAC;MAAA,OAAAV,mBAAA,CAAAC,KAAA,OAAAC,SAAA;IAAA;IACDH,kBAAkB,CAAC,CAAC;IACpB,OAAO,MAAM;MACXD,WAAW,GAAG,IAAI;IACpB,CAAC;EACH,CAAC,EACD,CAACT,UAAU,EAAEK,WAAW,CAC1B,CAAC;EAED,OAAOJ,OAAO;AAChB;AAEA,eAAeF,SAAS"}
|