Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: revert all previous changes #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 35 additions & 48 deletions demo/api.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 35 additions & 48 deletions demo/index.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 35 additions & 48 deletions src/auro-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,61 +52,31 @@ export class AuroTable extends LitElement {
AuroLibraryRuntimeUtils.prototype.registerComponent(name, AuroTable);
}

updated(changedProperties) {
if (changedProperties.has('columnHeaders')) {
this.extractHeaders();
}

if (changedProperties.has('componentData')) {
this.extractRows();
}
}

firstUpdated() {
// Add the tag name as an attribute if it is different than the component name
this.runtimeUtils.handleComponentTagRename(this, 'auro-table');
}

/**
* @private
* @param { Array } columns - Titles for column headers.
* @param { Array } data - TD content.
* @returns { void }
*/
extractHeaders() {
if (this.columnHeaders) {
const headerRow = this.shadowRoot.querySelector('thead tr');
extractRows(columns, data) {
const rows = [];

headerRow.innerHTML = '';
data.forEach((index) => {
const row = [];

this.columnHeaders.forEach((header) => {
const th = document.createElement('th');

th.innerHTML = header;
headerRow.appendChild(th);
columns.forEach((column) => {
row.push(index[column]);
});
}
}

/**
* @private
* @returns { void }
*/
extractRows() {
const tableBody = this.shadowRoot.querySelector('tbody');

if (this.componentData && this.columnHeaders) {
this.componentData.forEach((row) => {
const tr = document.createElement('tr');

this.columnHeaders.forEach((column) => {
const td = document.createElement('td');
const content = row[column] || '';
td.innerHTML = content;
tr.appendChild(td);
});
rows.push(row);
});

tableBody.appendChild(tr);
});
}
return rows;
}

// function that renders the HTML and CSS into the scope of the component
Expand All @@ -115,12 +85,29 @@ export class AuroTable extends LitElement {
'nowrap': this.nowrap,
};

return html`
<table>
<thead><tr></tr></thead>
<tbody class="${classMap(classes)}">
</tbody>
</table>
`;
if (this.columnHeaders && this.componentData) {
return html`
<table>
<thead>
<tr>
${this.columnHeaders.map((header) => html`
<th>${header}</th>
`)}
</tr>
</thead>
<tbody class="${classMap(classes)}">
${this.extractRows(this.columnHeaders, this.componentData).map((row) => html`
<tr>
${row.map((data) => html`
<td>${data}</td>
`)}
</tr>
`)}
</tbody>
</table>
`;
}

return html``;
}
}