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

Update adds support for diffing element defenitions with slots #1

Open
wants to merge 7 commits into
base: main
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
registry-url: https://registry.npmjs.org/

- name: Install
run: npm ci
run: npm i

- name: Run Tests
run: npm test
Expand All @@ -49,7 +49,7 @@ jobs:
registry-url: https://registry.npmjs.org/

- name: Install
run: npm ci
run: npm i

- name: Run Tests
run: npm test
Expand Down
20 changes: 18 additions & 2 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,28 @@ const MorphdomMixin = (superclass) => class extends superclass {
const tmp = this.render({
html: this.html,
state: this.state
})
}).trim()

const updated = document.createElement('div')
updated.innerHTML = tmp.trim()
updated.innerHTML = tmp

if (this['scrubTemplate']) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious as why you wrote it this way instead of:

if (typeof this. scrubTemplate === 'function') {

this.scrubTemplate(updated)
}

const root = this.shadowRoot
? this.shadowRoot
: this

if (!this.shadowRoot && this['expandSlots']) {
const slotEl = document.createElement('div')
const slottedElements = root.querySelectorAll(`${this.tagName.toLowerCase()} > [slot=""]`)
for (const value of slottedElements.values()) {
slotEl.appendChild(value)
}
updated.innerHTML = this.expandSlots(slotEl.innerHTML, updated.innerHTML)
}

morphdom(
root,
updated,
Expand Down
Loading
Loading