aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/root-helpers/utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/root-helpers/utils.ts')
-rw-r--r--client/src/root-helpers/utils.ts38
1 files changed, 0 insertions, 38 deletions
diff --git a/client/src/root-helpers/utils.ts b/client/src/root-helpers/utils.ts
index 06591b95e..00bd92411 100644
--- a/client/src/root-helpers/utils.ts
+++ b/client/src/root-helpers/utils.ts
@@ -1,5 +1,3 @@
1import { environment } from '../environments/environment'
2
3function objectToUrlEncoded (obj: any) { 1function objectToUrlEncoded (obj: any) {
4 const str: string[] = [] 2 const str: string[] = []
5 for (const key of Object.keys(obj)) { 3 for (const key of Object.keys(obj)) {
@@ -21,41 +19,6 @@ function copyToClipboard (text: string) {
21 document.body.removeChild(el) 19 document.body.removeChild(el)
22} 20}
23 21
24// Thanks: https://github.com/uupaa/dynamic-import-polyfill
25function importModule (path: string) {
26 return new Promise((resolve, reject) => {
27 const vector = '$importModule$' + Math.random().toString(32).slice(2)
28 const script = document.createElement('script')
29
30 const destructor = () => {
31 delete window[ vector ]
32 script.onerror = null
33 script.onload = null
34 script.remove()
35 URL.revokeObjectURL(script.src)
36 script.src = ''
37 }
38
39 script.defer = true
40 script.type = 'module'
41
42 script.onerror = () => {
43 reject(new Error(`Failed to import: ${path}`))
44 destructor()
45 }
46 script.onload = () => {
47 resolve(window[ vector ])
48 destructor()
49 }
50 const absURL = (environment.apiUrl || window.location.origin) + path
51 const loader = `import * as m from "${absURL}"; window.${vector} = m;` // export Module
52 const blob = new Blob([ loader ], { type: 'text/javascript' })
53 script.src = URL.createObjectURL(blob)
54
55 document.head.appendChild(script)
56 })
57}
58
59function wait (ms: number) { 22function wait (ms: number) {
60 return new Promise<void>(res => { 23 return new Promise<void>(res => {
61 setTimeout(() => res(), ms) 24 setTimeout(() => res(), ms)
@@ -64,7 +27,6 @@ function wait (ms: number) {
64 27
65export { 28export {
66 copyToClipboard, 29 copyToClipboard,
67 importModule,
68 objectToUrlEncoded, 30 objectToUrlEncoded,
69 wait 31 wait
70} 32}