Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
feat(page-element): unique id for each page-element
Browse files Browse the repository at this point in the history
The id is based on the location of the element in the element tree
  • Loading branch information
telemetry-tech-user authored and lkuechler committed Feb 19, 2018
1 parent c009cd2 commit 79bbb1a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/store/page/page-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,23 @@ export class PageElement {
return this.parent.children.indexOf(this);
}

/**
* Returns the unique ID of this element
* @return an array of numbers which represents the unique ID
*/
public getId(): number[] {
if (!this.parent) {
return [0];
}

if (!this.parent.parent) {
return [0, this.getIndex()];
}

const parentID = this.parent.getId();
return [...parentID, this.getIndex()];
}

/**
* Returns the parent page element if this is not the root element.
* @return The parent page element or undefined.
Expand Down

0 comments on commit 79bbb1a

Please sign in to comment.