From 427dae885c83adf11c5a17cc621e736956751583 Mon Sep 17 00:00:00 2001 From: Edoardo Cavazza Date: Mon, 2 Oct 2023 17:44:43 +0200 Subject: [PATCH] Auto patch window if browser --- .changeset/calm-tools-tease.md | 5 +++++ .changeset/pre.json | 8 ++------ src/Realm.js | 6 +----- src/index.js | 8 +++++++- 4 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 .changeset/calm-tools-tease.md diff --git a/.changeset/calm-tools-tease.md b/.changeset/calm-tools-tease.md new file mode 100644 index 0000000..4ff7491 --- /dev/null +++ b/.changeset/calm-tools-tease.md @@ -0,0 +1,5 @@ +--- +'@chialab/quantum': patch +--- + +Auto patch window if browser. diff --git a/.changeset/pre.json b/.changeset/pre.json index 09ee9f9..29de8d4 100644 --- a/.changeset/pre.json +++ b/.changeset/pre.json @@ -1,12 +1,8 @@ { "mode": "pre", - "tag": "latest", + "tag": "alpha", "initialVersions": { "@chialab/quantum": "0.0.1" }, - "changesets": [ - "kind-buckets-drop", - "spicy-worms-double", - "three-trainers-design" - ] + "changesets": ["kind-buckets-drop", "spicy-worms-double", "three-trainers-design"] } diff --git a/src/Realm.js b/src/Realm.js index 2e14163..3ac3839 100644 --- a/src/Realm.js +++ b/src/Realm.js @@ -1,5 +1,3 @@ -import { extend } from './extend.js'; - /** * @typedef {{ addedNodes: ChildNode[]; removedNodes: ChildNode[]; previousSibling: ChildNode | null; nextSibling: ChildNode | null }} MutationRecord */ @@ -14,11 +12,9 @@ const REALM_PARENT_SYMBOL = Symbol(); /** * Create and attach a realm for a node. * @param {HTMLElement & { [REALM_SYMBOL]?: Realm }} node The root node. - * @param {Window & typeof globalThis} [namespace] The namespace to use as DOM environment. * @returns The realm instance. */ -export function attachRealm(node, namespace = window) { - extend(namespace); +export function attachRealm(node) { if (REALM_SYMBOL in node) { throw new Error('Node already has a realm'); } diff --git a/src/index.js b/src/index.js index 768d005..3ca12be 100644 --- a/src/index.js +++ b/src/index.js @@ -1,2 +1,8 @@ -export { extend } from './extend.js'; +import { extend } from './extend.js'; + +export { extend }; export { Realm, attachRealm, getRealm } from './Realm.js'; + +if (typeof window !== 'undefined') { + extend(window); +}