Skip to content

Commit 0e3916a

Browse files
committed
Handle Promise when call expand function in hpainter
Let do complex work when exapnd item
1 parent 5f11ee2 commit 0e3916a

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

modules/gui/HierarchyPainter.mjs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { version, gStyle, httpRequest, create, createHttpRequest, loadScript, loadModules, decodeUrl,
22
source_dir, settings, internals, browser, findFunction, toJSON,
3-
isArrayProto, isRootCollection, isBatchMode, isNodeJs, isObject, isFunc, isStr, _ensureJSROOT,
3+
isArrayProto, isRootCollection, isBatchMode, isNodeJs, isObject, isFunc, isStr, getPromise, _ensureJSROOT,
44
clTList, clTMap, clTObjString, clTKey, clTFile, clTText, clTLatex, clTColor, clTStyle,
55
getKindForType, getTypeForKind, kInspect, isPromise } from '../core.mjs';
66
import { select as d3_select } from '../d3.mjs';
@@ -1367,7 +1367,8 @@ class HierarchyPainter extends BasePainter {
13671367

13681368
if (this.with_icons) {
13691369
// in normal hierarchy check precisely if item can be expand
1370-
if (!hitem._more && !hitem._expand && !this.canExpandItem(hitem)) return false;
1370+
if (!hitem._more && !hitem._expand && !this.canExpandItem(hitem))
1371+
return false;
13711372
}
13721373

13731374
const pr = this.expandItem(this.itemFullName(hitem));
@@ -1694,10 +1695,13 @@ class HierarchyPainter extends BasePainter {
16941695
}
16951696
}
16961697

1697-
if (hitem._childs) can_expand = false;
1698+
if (hitem._childs)
1699+
can_expand = false;
16981700

1699-
if (can_draw === undefined) can_draw = sett.draw;
1700-
if (can_expand === undefined) can_expand = sett.expand || sett.get_expand;
1701+
if (can_draw === undefined)
1702+
can_draw = sett.draw;
1703+
if (can_expand === undefined)
1704+
can_expand = sett.expand || sett.get_expand;
17011705

17021706
if (can_draw && can_expand && !drawopt) {
17031707
// if default action specified as expand, disable drawing
@@ -2650,8 +2654,10 @@ class HierarchyPainter extends BasePainter {
26502654
/** @summary Check if item can be (potentially) expand
26512655
* @private */
26522656
canExpandItem(item) {
2653-
if (!item) return false;
2654-
if (item._expand) return true;
2657+
if (!item)
2658+
return false;
2659+
if (item._expand)
2660+
return true;
26552661
const handle = getDrawHandle(item._kind, '::expand');
26562662
return handle && canExpandHandle(handle);
26572663
}
@@ -2696,15 +2702,18 @@ class HierarchyPainter extends BasePainter {
26962702

26972703
// try to use expand function
26982704
if (_obj && isFunc(_item._expand)) {
2699-
if (_item._expand(_item, _obj)) {
2700-
_item._isopen = true;
2701-
if (_item._parent && !_item._parent._isopen) {
2702-
_item._parent._isopen = true; // also show parent
2703-
if (!silent)
2704-
hpainter.updateTreeNode(_item._parent);
2705-
} else if (!silent)
2706-
hpainter.updateTreeNode(_item, d3cont);
2707-
return _item;
2705+
const res = _item._expand(_item, _obj);
2706+
if (res) {
2707+
return getPromise(res).then(() => {
2708+
_item._isopen = true;
2709+
if (_item._parent && !_item._parent._isopen) {
2710+
_item._parent._isopen = true; // also show parent
2711+
if (!silent)
2712+
hpainter.updateTreeNode(_item._parent);
2713+
} else if (!silent)
2714+
hpainter.updateTreeNode(_item, d3cont);
2715+
return _item;
2716+
});
27082717
}
27092718
}
27102719

0 commit comments

Comments
 (0)