Skip to content

Commit

Permalink
component.Base: method order
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiu committed Jan 25, 2025
1 parent 97b7eff commit f2fd7f3
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions src/component/Base.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1696,42 +1696,6 @@ class Component extends Base {
return Rectangle.clone(result)
}

/**
* In case you are sure a DOMRect exists, use getDomRect()
* Otherwise you can wait for it using this method.
* @example:
* await this.render(true);
* await this.waitForDomRect();
* @param {Object} opts
* @param {String} opts.appName=this.appName
* @param {Number} opts.attempts=10 Reruns in case the rect height or width equals 0
* @param {Number} opts.delay=50 Time in ms before checking again
* @param {String[]|String} opts.id=this.id
* @returns {Promise<Neo.util.Rectangle|Neo.util.Rectangle[]>}
*/
async waitForDomRect({appName=this.appName, attempts=10, delay=50, id=this.id}) {
let me = this,
result = await me.getDomRect(id, appName),
reRun = false;

if (Array.isArray(result)) {
result.forEach(rect => {
if (rect.height < 1 || rect.width < 1) {
reRun = true
}
})
} else if (result.height < 1 || result.width < 1) {
reRun = true
}

if (reRun && attempts > 0) {
await me.timeout(delay);
return await me.waitForDomRect({appName, attempts: attempts-1, delay, id})
}

return result
}

/**
* Honors different item roots for mount / render OPs
* @returns {String}
Expand Down Expand Up @@ -2758,6 +2722,42 @@ class Component extends Base {

me.hasUnmountedVdomChanges = !mounted && me.hasBeenMounted
}

/**
* In case you are sure a DOMRect exists, use getDomRect()
* Otherwise you can wait for it using this method.
* @example:
* await this.render(true);
* await this.waitForDomRect();
* @param {Object} opts
* @param {String} opts.appName=this.appName
* @param {Number} opts.attempts=10 Reruns in case the rect height or width equals 0
* @param {Number} opts.delay=50 Time in ms before checking again
* @param {String[]|String} opts.id=this.id
* @returns {Promise<Neo.util.Rectangle|Neo.util.Rectangle[]>}
*/
async waitForDomRect({appName=this.appName, attempts=10, delay=50, id=this.id}) {
let me = this,
result = await me.getDomRect(id, appName),
reRun = false;

if (Array.isArray(result)) {
result.forEach(rect => {
if (rect.height < 1 || rect.width < 1) {
reRun = true
}
})
} else if (result.height < 1 || result.width < 1) {
reRun = true
}

if (reRun && attempts > 0) {
await me.timeout(delay);
return await me.waitForDomRect({appName, attempts: attempts-1, delay, id})
}

return result
}
}

/**
Expand Down

0 comments on commit f2fd7f3

Please sign in to comment.