Last active
January 22, 2021 21:44
-
-
Save steveruizok/403d7359ab09fcf510a93e56274d24db to your computer and use it in GitHub Desktop.
Dream API for psuedo-bundled code.
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 characters
async function getConcatenatedCodeFromWorker(...args: any[]) { | |
return "..." | |
} | |
async function getRunnableBundle< | |
Files extends Record<string, string>, | |
Entry extends keyof Files | |
>({ | |
files, | |
entry, | |
scope, | |
}: { | |
files: Files | |
entry: Entry | |
scope: Record<string, any> | |
}) { | |
const concatenatedCode = await getConcatenatedCodeFromWorker(files, entry) | |
const args = Object.keys(scope) | |
const vargs = Object.values(scope) | |
return () => Function(...args)(...vargs, concatenatedCode) | |
} | |
const run = getRunnableBundle({ | |
files: { | |
"name.ts": ` export const name = "Steve"`, | |
"index.ts": `import * as React from "reacy" | |
import { name } from "./ | |
function App() { | |
return <div>Hello {name}!</div> | |
} | |
ReactDOM.render(<App/>, elm)`, | |
}, | |
entry: "index.ts", | |
scope: { | |
React, | |
ReactDOM, | |
elm: document.getElementById("root") | |
}, | |
}) | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.