Skip to content

Commit

Permalink
perf: cache selector creation
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoFiers committed Jun 12, 2024
1 parent 2481379 commit cb5c331
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/core/utils/dq-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,32 @@ DqElement.prototype = {
* @return {String}
*/
get selector() {
return this.spec.selector || [getSelector(this.element, this._options)];
if (!this.spec.selector) {
this.spec.selector = [getSelector(this.element, this._options)];
}
return this.spec.selector;
},

/**
* A unique CSS selector for the element, including its ancestors down to the root node
* @return {String}
*/
get ancestry() {
return this.spec.ancestry || [getAncestry(this.element)];
if (!this.spec.ancestry) {
this.spec.ancestry = [getAncestry(this.element)];
}
return this.spec.ancestry;
},

/**
* Xpath to the element
* @return {String}
*/
get xpath() {
return this.spec.xpath || [getXpath(this.element)];
if (!this.spec.xpath) {
this.spec.xpath = [getXpath(this.element)];
}
return this.spec.xpath;
},

/**
Expand Down

0 comments on commit cb5c331

Please sign in to comment.