@@ -63,21 +63,26 @@ qx.Class.define("qxl.datagrid.source.tree.TreeDataSource", {
63
63
* @typedef RowMetaData
64
64
* @property {qx.core.Object } node the node object for the row
65
65
* @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 */
70
72
__rowMetaDatas : null ,
71
73
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 */
73
75
__rowMetaDataByNode : null ,
74
76
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 */
76
78
__queue : null ,
77
79
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 */
79
81
__promiseQueueEmpty : null ,
80
82
83
+ /**@type {boolean } */
84
+ __hasExecution : false ,
85
+
81
86
/**
82
87
* Apply for root
83
88
*/
@@ -87,6 +92,8 @@ qx.Class.define("qxl.datagrid.source.tree.TreeDataSource", {
87
92
this . __rowMetaDatas = [ ] ;
88
93
if ( oldValue ) {
89
94
let oldRowMetaDatas = this . __rowMetaDatas ;
95
+ this . __queue = [ ] ;
96
+ await this . flushQueue ( ) ;
90
97
this . __rowMetaDataByNode = { } ;
91
98
this . __rowMetaDatas = [ ] ;
92
99
for ( let rowMeta in oldRowMetaDatas ) {
@@ -198,46 +205,46 @@ qx.Class.define("qxl.datagrid.source.tree.TreeDataSource", {
198
205
async _expandNode ( node ) {
199
206
let inspector = this . getNodeInspectorFactory ( ) ( node ) ;
200
207
let children = await inspector . getChildrenOf ( node ) ;
201
- let rowMetadata = this . _getNodeMetaData ( node ) ;
202
- if ( ! rowMetadata ) {
208
+ let rowMeta = this . _getNodeMetaData ( node ) ;
209
+ if ( ! rowMeta ) {
203
210
throw new Error ( `Cannot find ${ node } in rows` ) ;
204
211
}
205
- if ( rowMetadata . childRowMetas || ! rowMetadata . canHaveChildren ) {
212
+ if ( rowMeta . childRowMetas || ! rowMeta . canHaveChildren ) {
206
213
return ;
207
214
}
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 ) ;
210
217
let childRowMetas = [ ] ;
211
218
for ( let childNode of children ) {
212
219
if ( ! childNode ) {
213
220
continue ;
214
221
}
215
222
const childInspector = this . getNodeInspectorFactory ( ) ( childNode ) ;
216
- let childRowMeta = this . __createRowMetaData ( childNode , rowMetadata . level + 1 ) ;
223
+ let childRowMeta = this . __createRowMetaData ( childNode , rowMeta . level + 1 ) ;
217
224
childRowMeta . canHaveChildren = childInspector . canHaveChildren ( childNode ) ;
218
225
childRowMetas . push ( childRowMeta ) ;
219
- childRowMeta . parentMeta = rowMetadata ;
226
+ childRowMeta . parentMeta = rowMeta ;
220
227
this . __rowMetaDataByNode [ childNode . toHashCode ( ) ] = childRowMeta ;
221
228
}
222
229
let before = this . __rowMetaDatas . slice ( 0 , parentRowIndex + 1 ) ;
223
230
let after = parentRowIndex == this . __rowMetaDatas . length - 1 ? [ ] : this . __rowMetaDatas . slice ( parentRowIndex + 1 ) ;
224
231
qx . lang . Array . append ( before , childRowMetas ) ;
225
232
qx . lang . Array . append ( before , after ) ;
226
- rowMetadata . childRowMetas = childRowMetas ;
233
+ rowMeta . childRowMetas = childRowMetas ;
227
234
this . __rowMetaDatas = before ;
228
235
this . fireDataEvent ( "changeSize" , this . getSize ( ) ) ;
229
236
} ,
230
237
231
238
/**
232
239
* Reveals node in tree, even if it's not currently shown.
233
240
* All ancestors of node are expanded.
234
- * @param {qx.data .Object } node
241
+ * @param {qx.core .Object } node
235
242
*/
236
243
async revealNode ( node ) {
237
244
/**
238
245
* 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.
241
248
*/
242
249
const getPathToNode = async node => {
243
250
let path = new qx . data . Array ( ) ;
@@ -273,7 +280,7 @@ qx.Class.define("qxl.datagrid.source.tree.TreeDataSource", {
273
280
* @param {* } node
274
281
*/
275
282
async _collapseNode ( node ) {
276
- let rowMeta = this . __rowMetaDataByNode [ node . toHashCode ( ) ] ;
283
+ let rowMeta = this . _getNodeMetaData ( node ) ;
277
284
if ( ! rowMeta ) {
278
285
throw new Error ( `Cannot find ${ node } in rows` ) ;
279
286
}
@@ -298,7 +305,7 @@ qx.Class.define("qxl.datagrid.source.tree.TreeDataSource", {
298
305
299
306
/**
300
307
* 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
302
309
*/
303
310
_removeChildRows ( rowMeta ) {
304
311
let toRemove = [ ] ;
@@ -325,7 +332,7 @@ qx.Class.define("qxl.datagrid.source.tree.TreeDataSource", {
325
332
* completed
326
333
*
327
334
* @param {Function } fn
328
- * @returns {* } whatever the function returns
335
+ * @returns {Promise<void> }
329
336
*/
330
337
async queue ( fn ) {
331
338
this . __queue . push ( fn ) ;
@@ -338,11 +345,13 @@ qx.Class.define("qxl.datagrid.source.tree.TreeDataSource", {
338
345
* Executes the next function in the queue
339
346
*/
340
347
async __executeNextQueue ( ) {
348
+ this . __hasExecution = true ;
341
349
if ( this . __queue . length == 0 ) {
342
350
if ( this . __promiseQueueEmpty ) {
343
351
this . __promiseQueueEmpty . resolve ( ) ;
344
352
this . __promiseQueueEmpty = null ;
345
353
}
354
+ this . __hasExecution = false ;
346
355
return ;
347
356
}
348
357
let fn = this . __queue [ 0 ] ;
@@ -355,6 +364,9 @@ qx.Class.define("qxl.datagrid.source.tree.TreeDataSource", {
355
364
* Called to flush the queue and wait for all the promises to be complete
356
365
*/
357
366
async flushQueue ( ) {
367
+ if ( ! this . __hasExecution ) {
368
+ return ;
369
+ }
358
370
if ( this . __promiseQueueEmpty ) {
359
371
await this . __promiseQueueEmpty ;
360
372
} else if ( this . __queue . length ) {
0 commit comments