Skip to content

Commit

Permalink
refactor: use helper to check node type
Browse files Browse the repository at this point in the history
  • Loading branch information
TremayneChrist committed Jul 31, 2021
1 parent 1efb026 commit 365a6bd
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/utils/register.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { scheduler } from "./scheduler";
import { documentEvents } from './events';
import { isDocument } from "./element";

/**
* Global count of all observed elements.
Expand Down Expand Up @@ -42,7 +43,7 @@ const mo = new MutationObserver(handleEvent);
*/
const getDocument = (node: Node): Document | ShadowRoot | null => {
const root = node.getRootNode ? node.getRootNode({ composed: node.nodeType === 11 }) : node.ownerDocument;
if (root && root !== node && !(/9|11/).test(root.nodeType.toString())) {
if (root && root !== node && !isDocument(root)) {
return getDocument(root);
}
return root as Document | ShadowRoot | null;
Expand Down

0 comments on commit 365a6bd

Please sign in to comment.