Skip to content

Commit

Permalink
Small refactor to Element and Container (#355)
Browse files Browse the repository at this point in the history
  • Loading branch information
willeastcott authored May 24, 2024
1 parent f081ef4 commit 0312577
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
9 changes: 1 addition & 8 deletions src/components/Container/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,7 @@ class Container extends Element {
* @param index - The index to move the element to.
*/
move(element: Element, index: number) {
let idx = -1;
for (let i = 0; i < this.dom.childNodes.length; i++) {
if (this.dom.childNodes[i].ui === element) {
idx = i;
break;
}
}
const idx = Array.prototype.indexOf.call(this.dom.childNodes, element.dom);

if (idx === -1) {
this.appendBefore(element, this.dom.childNodes[index]);
Expand Down Expand Up @@ -579,7 +573,6 @@ class Container extends Element {
* @param node.root - The root node of the dom structure.
* @param node.children - The children of the root node.
* @returns The recursively appended element node.
*
*/
protected _buildDomNode(node: { [x: string]: any; root?: any; children?: any; }): Container {
const keys = Object.keys(node);
Expand Down
12 changes: 3 additions & 9 deletions src/components/Element/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -892,10 +892,7 @@ class Element extends Events {
* Gets / sets the width of the Element in pixels. Can also be an empty string to remove it.
*/
set width(value: number | string) {
if (typeof value === 'number') {
value = String(value) + 'px';
}
this.style.width = value;
this.style.width = typeof value === 'number' ? `${value}px` : value;
}

get width(): number {
Expand All @@ -906,10 +903,7 @@ class Element extends Events {
* Gets / sets the height of the Element in pixels. Can also be an empty string to remove it.
*/
set height(value: number | string) {
if (typeof value === 'number') {
value = String(value) + 'px';
}
this.style.height = value;
this.style.height = typeof value === 'number' ? `${value}px` : value;
}

get height(): number {
Expand Down Expand Up @@ -1102,7 +1096,7 @@ class Element extends Events {

// Declare an additional property on the base Node interface that references the owner Element
declare global {
interface Node { // eslint-disable-line no-unused-vars
interface Node {
ui: Element;
}
}
Expand Down

0 comments on commit 0312577

Please sign in to comment.