Skip to content

Commit

Permalink
Merge pull request HalseySpicy#122 from youngleish/patch-1
Browse files Browse the repository at this point in the history
fix: removeChild HalseySpicy#121
  • Loading branch information
caoxiemeihao authored May 7, 2022
2 parents a0b7597 + bf251f8 commit 5c569d5
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions packages/preload/loading.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


/**
* https://tobiasahlin.com/spinkit
* https://connoratherton.com/loaders
Expand Down Expand Up @@ -45,12 +43,25 @@ export function useLoading() {

return {
appendLoading() {
document.head.appendChild(oStyle)
document.body.appendChild(oDiv)
safe.append(document.head, oStyle)
safe.append(document.body, oDiv)
},
removeLoading() {
document.head.removeChild(oStyle)
document.body.removeChild(oDiv)
safe.remove(document.head, oStyle)
safe.remove(document.body, oDiv)
},
}
}

const safe = {
append(parent: HTMLElement, child: HTMLElement) {
if (!Array.from(parent.children).find(e => e === child)) {
return parent.appendChild(child)
}
},
remove(parent: HTMLElement, child: HTMLElement) {
if (Array.from(parent.children).find(e => e === child)) {
return parent.removeChild(child)
}
},
}

0 comments on commit 5c569d5

Please sign in to comment.