Revisions
-
samthor revised this gist
Jul 25, 2017 . 2 changed files with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ // usage: // importScript('./path/to/script.js').then((allExports) => { .... })); function importScript(path) { let entry = window.importScript.__db[path]; if (entry === undefined) { This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +0,0 @@ -
samthor revised this gist
Jun 16, 2017 . 2 changed files with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,4 +17,4 @@ function importScript(path) { return entry.promise; } importScript.__db = {}; window['importScript'] = importScript; // needed if we ourselves are in a module This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1 @@ function c(a){var b=c.a[a];if(void 0===b){var d=a.replace("'","\\'"),e=Object.assign(document.createElement("script"),{type:"module",textContent:"import * as x from '"+d+"'; importScript.a['"+d+"'].resolve(x);"}),b=c.a[a]={};b.b=new Promise(function(a,d){b.resolve=a;e.onerror=d});document.head.appendChild(e);e.remove()}return b.b}c.a={};window.importScript=c; -
samthor revised this gist
Jun 16, 2017 . 2 changed files with 20 additions and 16 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,20 @@ function importScript(path) { let entry = window.importScript.__db[path]; if (entry === undefined) { const escape = path.replace(`'`, `\\'`); const script = Object.assign(document.createElement('script'), { type: 'module', textContent: `import * as x from '${escape}'; importScript.__db['${escape}'].resolve(x);`, }); entry = importScript.__db[path] = {}; entry.promise = new Promise((resolve, reject) => { entry.resolve = resolve; script.onerror = reject; }); document.head.appendChild(script); script.remove(); } return entry.promise; } importScript.__db = {}; window.importScript = importScript; // needed if we ourselves are in a module This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,2 +1 @@ function c(a){var b=c.a[a];if(void 0===b){var d=a.replace("'","\\'"),e=Object.assign(document.createElement("script"),{type:"module",textContent:"import * as x from '"+d+"'; importScript.__db['"+d+"'].resolve(x);"}),b=c.a[a]={};b.b=new Promise(function(a,d){b.resolve=a;e.onerror=d});document.head.appendChild(e);e.remove()}return b.b}c.a={};window.importScript=c; -
surma created this gist
May 6, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ _registry = {}; importPolyfill = path => { if(!(path in _registry)) { const entry = _registry[path] = {}; entry.promise = new Promise(resolve => entry.resolve = resolve); document.head.appendChild(Object.assign( document.createElement('script'), { type: 'module', innerText: `import * as X from '${path}'; _registry['${path}'].resolve(X);`, } )); } return _registry[path].promise; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ r={},importPolyfill=(a)=>{if(!(a in r)){const b=r[a]={};b.p=new Promise((c)=>b.r=c),document.head.appendChild(Object.assign(document.createElement('script'),{type:'module',innerText:`import * as X from '${a}'; r['${a}'].r(X);`}))}return r[a].p};