Skip to content

Commit 9475053

Browse files
author
Avaer Kazmer
committed
Move replace document function into utils
1 parent 196e58f commit 9475053

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

src/Window.js

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import symbols from './symbols.js';
2323

2424
import * as XR from './XR.js';
2525
import utils from './utils.js';
26-
const {_elementGetter, _elementSetter} = utils;
26+
const {_elementGetter, _elementSetter, _replaceDocument} = utils;
2727

2828
import XRIFrame from './xr-iframe.js';
2929
import XRSite from './xr-site.js';
@@ -740,26 +740,7 @@ const _fetchText = src => fetch(src)
740740
}
741741
} */
742742

743-
document.open();
744-
document.write(htmlString);
745-
document.close();
746-
747-
if (document.readyState !== 'complete') {
748-
await new Promise((accept, reject) => {
749-
document.addEventListener('readystatechange', () => {
750-
if (document.readyState === 'complete') {
751-
accept();
752-
}
753-
});
754-
});
755-
}
756-
await new Promise((accept, reject) => {
757-
const script = document.createElement('script');
758-
script.onload = accept;
759-
script.onerror = reject;
760-
script.src = `data:application/javascript,1`;
761-
document.body.appendChild(script);
762-
});
743+
await _replaceDocument(htmlString);
763744

764745
})(self).then(() => {
765746
self._onbootstrap({

src/utils.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,28 @@ const _makeNullPromise = () => {
122122
};
123123
module.exports._makeNullPromise = _makeNullPromise;
124124

125+
const _replaceDocument = async htmlString => {
126+
document.open();
127+
document.write(htmlString);
128+
document.close();
129+
130+
if (document.readyState !== 'complete') {
131+
await new Promise((accept, reject) => {
132+
document.addEventListener('readystatechange', () => {
133+
if (document.readyState === 'complete') {
134+
accept();
135+
}
136+
});
137+
});
138+
}
139+
await new Promise((accept, reject) => {
140+
const script = document.createElement('script');
141+
script.onload = accept;
142+
script.onerror = reject;
143+
script.src = `data:application/javascript,1`;
144+
document.body.appendChild(script);
145+
});
146+
};
147+
module.exports._replaceDocument = _replaceDocument;
148+
125149
export default module.exports;

0 commit comments

Comments
 (0)