Skip to content

Commit 78c78c9

Browse files
committed
Merge commit 'e000710e2fa2d0cf9eb10889edc973fdf515b826'
# Conflicts: # source/class/qxl/datagrid/source/tree/TreeDataSource.js
2 parents 1731820 + e000710 commit 78c78c9

File tree

1 file changed

+33
-21
lines changed

1 file changed

+33
-21
lines changed

source/class/qxl/datagrid/source/tree/TreeDataSource.js

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,26 @@ qx.Class.define("qxl.datagrid.source.tree.TreeDataSource", {
6363
* @typedef RowMetaData
6464
* @property {qx.core.Object} node the node object for the row
6565
* @property {Integer} level indentation level
66-
* @property {Boolean} canHaveChildren whether the node might have children
67-
* @property {qxl.datagrid.binding.Bindings} childrenChangeListener Binding object for the change listener of the node's children
68-
*
69-
* @type{RowMetaData[]} array of objects for each visible row*/
66+
* @property {boolean} canHaveChildren whether the node might have children
67+
* @property {qxl.datagrid.binding.Bindings} childrenChangeBinding Binding object for the change listener of the node's children
68+
* @prop {RowMetaData[]} [childRowMetas] array of child row metadata
69+
*/
70+
71+
/** @type {RowMetaData[]} array of objects for each visible row */
7072
__rowMetaDatas: null,
7173

72-
/** @type{Map<String,RowMetaData>} map of row metadatas for all visible rows, indexed by hash code of the node */
74+
/** @type {Record<string, RowMetaData>} map of row metadatas for all visible rows, indexed by hash code of the node */
7375
__rowMetaDataByNode: null,
7476

75-
/** @type{Promise[]?} queue of promises of background actions, eg loading nodes */
77+
/** @type {(() => Promise<void>)[] | null} queue of promises of background actions, eg loading nodes */
7678
__queue: null,
7779

78-
/** @type{Promise} resolves when the queue empties, is null if the queue is already empty */
80+
/** @type {Promise<void>} resolves when the queue empties, is null if the queue is already empty */
7981
__promiseQueueEmpty: null,
8082

83+
/**@type {boolean} */
84+
__hasExecution: false,
85+
8186
/**
8287
* Apply for root
8388
*/
@@ -87,6 +92,8 @@ qx.Class.define("qxl.datagrid.source.tree.TreeDataSource", {
8792
this.__rowMetaDatas = [];
8893
if (oldValue) {
8994
let oldRowMetaDatas = this.__rowMetaDatas;
95+
this.__queue = [];
96+
await this.flushQueue();
9097
this.__rowMetaDataByNode = {};
9198
this.__rowMetaDatas = [];
9299
for (let rowMeta in oldRowMetaDatas) {
@@ -198,46 +205,46 @@ qx.Class.define("qxl.datagrid.source.tree.TreeDataSource", {
198205
async _expandNode(node) {
199206
let inspector = this.getNodeInspectorFactory()(node);
200207
let children = await inspector.getChildrenOf(node);
201-
let rowMetadata = this._getNodeMetaData(node);
202-
if (!rowMetadata) {
208+
let rowMeta = this._getNodeMetaData(node);
209+
if (!rowMeta) {
203210
throw new Error(`Cannot find ${node} in rows`);
204211
}
205-
if (rowMetadata.childRowMetas || !rowMetadata.canHaveChildren) {
212+
if (rowMeta.childRowMetas || !rowMeta.canHaveChildren) {
206213
return;
207214
}
208-
rowMetadata.childrenChangeBinding = inspector.createChildrenChangeBinding(node, () => this.refreshNodeChildren(node));
209-
let parentRowIndex = this.__rowMetaDatas.indexOf(rowMetadata);
215+
rowMeta.childrenChangeBinding = inspector.createChildrenChangeBinding(node, () => this.refreshNodeChildren(node));
216+
let parentRowIndex = this.__rowMetaDatas.indexOf(rowMeta);
210217
let childRowMetas = [];
211218
for (let childNode of children) {
212219
if (!childNode) {
213220
continue;
214221
}
215222
const childInspector = this.getNodeInspectorFactory()(childNode);
216-
let childRowMeta = this.__createRowMetaData(childNode, rowMetadata.level + 1);
223+
let childRowMeta = this.__createRowMetaData(childNode, rowMeta.level + 1);
217224
childRowMeta.canHaveChildren = childInspector.canHaveChildren(childNode);
218225
childRowMetas.push(childRowMeta);
219-
childRowMeta.parentMeta = rowMetadata;
226+
childRowMeta.parentMeta = rowMeta;
220227
this.__rowMetaDataByNode[childNode.toHashCode()] = childRowMeta;
221228
}
222229
let before = this.__rowMetaDatas.slice(0, parentRowIndex + 1);
223230
let after = parentRowIndex == this.__rowMetaDatas.length - 1 ? [] : this.__rowMetaDatas.slice(parentRowIndex + 1);
224231
qx.lang.Array.append(before, childRowMetas);
225232
qx.lang.Array.append(before, after);
226-
rowMetadata.childRowMetas = childRowMetas;
233+
rowMeta.childRowMetas = childRowMetas;
227234
this.__rowMetaDatas = before;
228235
this.fireDataEvent("changeSize", this.getSize());
229236
},
230237

231238
/**
232239
* Reveals node in tree, even if it's not currently shown.
233240
* All ancestors of node are expanded.
234-
* @param {qx.data.Object} node
241+
* @param {qx.core.Object} node
235242
*/
236243
async revealNode(node) {
237244
/**
238245
* returns the path to a node (target) in the tree;
239-
* @param {qx.data.Object} node The node to return the path for
240-
* @returns {qx.data.Array} The path. It does not include the root and the node itself.
246+
* @param {qx.core.Object} node The node to return the path for
247+
* @returns {Promise<qx.data.Array>} The path. It does not include the root and the node itself.
241248
*/
242249
const getPathToNode = async node => {
243250
let path = new qx.data.Array();
@@ -273,7 +280,7 @@ qx.Class.define("qxl.datagrid.source.tree.TreeDataSource", {
273280
* @param {*} node
274281
*/
275282
async _collapseNode(node) {
276-
let rowMeta = this.__rowMetaDataByNode[node.toHashCode()];
283+
let rowMeta = this._getNodeMetaData(node);
277284
if (!rowMeta) {
278285
throw new Error(`Cannot find ${node} in rows`);
279286
}
@@ -298,7 +305,7 @@ qx.Class.define("qxl.datagrid.source.tree.TreeDataSource", {
298305

299306
/**
300307
* Recursively removes metatdats of children of specified row, from this.__rowMetaDatas
301-
* @param {JavaScript Object} row Metadata for row for which to remove children
308+
* @param {RowMetaData} rowMeta Metadata for row for which to remove children
302309
*/
303310
_removeChildRows(rowMeta) {
304311
let toRemove = [];
@@ -325,7 +332,7 @@ qx.Class.define("qxl.datagrid.source.tree.TreeDataSource", {
325332
* completed
326333
*
327334
* @param {Function} fn
328-
* @returns {*} whatever the function returns
335+
* @returns {Promise<void>}
329336
*/
330337
async queue(fn) {
331338
this.__queue.push(fn);
@@ -338,11 +345,13 @@ qx.Class.define("qxl.datagrid.source.tree.TreeDataSource", {
338345
* Executes the next function in the queue
339346
*/
340347
async __executeNextQueue() {
348+
this.__hasExecution = true;
341349
if (this.__queue.length == 0) {
342350
if (this.__promiseQueueEmpty) {
343351
this.__promiseQueueEmpty.resolve();
344352
this.__promiseQueueEmpty = null;
345353
}
354+
this.__hasExecution = false;
346355
return;
347356
}
348357
let fn = this.__queue[0];
@@ -355,6 +364,9 @@ qx.Class.define("qxl.datagrid.source.tree.TreeDataSource", {
355364
* Called to flush the queue and wait for all the promises to be complete
356365
*/
357366
async flushQueue() {
367+
if (!this.__hasExecution) {
368+
return;
369+
}
358370
if (this.__promiseQueueEmpty) {
359371
await this.__promiseQueueEmpty;
360372
} else if (this.__queue.length) {

0 commit comments

Comments
 (0)