Created
July 29, 2023 16:31
-
-
Save himself65/3c09230454612846873a2c0155be6d69 to your computer and use it in GitHub Desktop.
This file contains 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
import * as React from 'react' | |
const mockA = new Map([ | |
[ | |
'react', | |
React | |
], | |
]); | |
const module = new StaticModuleRecord(` | |
import { useState } from 'react'; | |
export const entry = () => { | |
const [state, setState] = useState(null) | |
return null; | |
} | |
`); | |
const c1 = new Compartment( | |
{}, | |
{}, | |
{ | |
name: 'first compartment', | |
} | |
); | |
const imports = new Map<string, Map<string, any>>(); | |
imports.set('a', mockA); | |
const f = c1.evaluate(module.__syncModuleProgram__); | |
f({ | |
imports: newUpdaters => { | |
for (const [module, moduleUpdaters] of newUpdaters) { | |
const moduleImports = imports.get(module); | |
if (moduleImports) { | |
for (const [importName, importUpdaters] of moduleUpdaters) { | |
const updateImport = (value: any) => { | |
for (const importUpdater of importUpdaters) { | |
importUpdater(value); | |
} | |
}; | |
if (moduleImports.has(importName)) { | |
updateImport(moduleImports.get(importName)); | |
} else { | |
console.log('import not found', importName); | |
} | |
} | |
} | |
} | |
}, | |
onceVar: { | |
entry: (f: any) => { | |
console.log('onceVar', f); | |
}, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment