Skip to content

Update uhtml to v2.7.5 #903

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
Jun 19, 2021
Merged

Update uhtml to v2.7.5 #903

merged 1 commit into from
Jun 19, 2021

Conversation

WebReflection
Copy link
Contributor

The following MR provides:

  • both delegate and tr based version of the keyed version
  • keyed benchmark uses the delegate, as discussed in Mark some 800/801s #878
  • all dependencies and dev dependencies have been updated
  • new syntax showcase has been added
  • changed the ugly uHTML for non keyed, made it uhtml

Thanks for considering this update.

@WebReflection
Copy link
Contributor Author

P.S. looks like various projects here are taking shortcuts for the select specific use case, assuming there will be only one selected node per time. I could cheat on uhtml code too with an early return, but that would not showcase real-world code (current MR).

Example

let selectedRow = null;
let selectedId = -1;

export default (state) => {
  const {data, selected} = state;
  if (selected !== selectedId) {
    if (selectedRow)
      selectedRow.classList.toggle('danger', false);
    selectedRow = document.getElementById(selectedId = selected);
    if (selectedRow) {
      selectedId = selected;
      selectedRow.classList.toggle('danger', true);
      return;
    }
  }
  return html.for(state)`
    <table class="table table-hover table-striped test-data"
      @click=${handler} .state=${state}>
      <tbody>${
      data.map(item => {
        const {id, label} = item;
        return html.for(data, id)`
        <tr id=${id}>
          <td class="col-md-1">${id}</td>
          <td class="col-md-4">
            <a data-action="select">${label}</a>
          </td>
          <td class="col-md-1">
            <a data-action="remove">
              <span class="glyphicon glyphicon-remove" aria-hidden="true" />
            </a>
          </td>
          <td class="col-md-6" />
        </tr>`;
      })
      }</tbody>
    </table>
  `;
};

This is whre uhtml would sit, if I used above code instead.

Screenshot from 2021-06-19 08-06-57

I am not asking for actions, just pointing out that these "issues" could be improved. The select case, if the node is retained and no diff is performed, or no idiomatic code is around that specific case, should be, imho, flagged too.

@krausest krausest merged commit afccc07 into krausest:master Jun 19, 2021
@krausest
Copy link
Owner

Thanks! Results are updated.

Toggling the css class directly should be flagged #772 (see also #878 (comment)).

@WebReflection
Copy link
Contributor Author

Thank you ❤ ... and yes, I did notice the updated results 🥳

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants