Skip to content

Commit

Permalink
feat: make document of updateDOM configurable (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jan 19, 2021
1 parent b6efb49 commit b48809a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/index.ts
Expand Up @@ -45,7 +45,7 @@ export type Head = {

removeHeadTags: (tags: HeadTag[]) => void

updateDOM: () => void
updateDOM: (document?: Document) => void
}

export interface HTMLResult {
Expand Down Expand Up @@ -126,7 +126,7 @@ const setAttrs = (el: Element, attrs: HeadAttrs) => {
el.setAttribute(HEAD_ATTRS_KEY, keys.join(','))
}

const insertTags = (tags: HeadTag[]) => {
const insertTags = (tags: HeadTag[], document = window.document) => {
const head = document.head
let headCountEl = head.querySelector(`meta[name="${HEAD_COUNT_KEY}"]`)
const headCount = headCountEl
Expand Down Expand Up @@ -234,8 +234,8 @@ export const createHead = () => {
})
},

updateDOM() {
insertTags(headTags)
updateDOM(document) {
insertTags(headTags, document)
},
}
return head
Expand Down

0 comments on commit b48809a

Please sign in to comment.