From b48809a8f005159bca7a09f32bdd3ec3213d7024 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Tue, 19 Jan 2021 19:34:23 +0800 Subject: [PATCH] feat: make `document` of updateDOM configurable (#7) --- src/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index de3440f..850da1e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -45,7 +45,7 @@ export type Head = { removeHeadTags: (tags: HeadTag[]) => void - updateDOM: () => void + updateDOM: (document?: Document) => void } export interface HTMLResult { @@ -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 @@ -234,8 +234,8 @@ export const createHead = () => { }) }, - updateDOM() { - insertTags(headTags) + updateDOM(document) { + insertTags(headTags, document) }, } return head