mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 13:04:30 -08:00
WIP
This commit is contained in:
@@ -380,6 +380,8 @@
|
||||
window.log = console.log
|
||||
|
||||
if(new URLSearchParams(window.location.search).get('leporello') == null) {
|
||||
await import('./src/launch.js');
|
||||
/*
|
||||
const {init} = await import('./src/index.js');
|
||||
(
|
||||
document.readyState == 'complete'
|
||||
@@ -390,6 +392,7 @@
|
||||
).then(() => {
|
||||
init(document.getElementById('app'))
|
||||
})
|
||||
*/
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
12
src/cmd.js
12
src/cmd.js
@@ -759,6 +759,7 @@ const load_dir = (state, dir) => {
|
||||
collect_files(dir).map(f => [f.path, f.contents])
|
||||
)
|
||||
|
||||
// Clear parse cache and rerun code
|
||||
return rerun_code({
|
||||
...state,
|
||||
// remove cache
|
||||
@@ -773,6 +774,15 @@ const create_file = (state, dir, current_module) => {
|
||||
return {...load_dir(state, dir), current_module}
|
||||
}
|
||||
|
||||
const open_run_window = state => {
|
||||
// After we reopen run window, we should reload external modules in the
|
||||
// context of new window. Clear external_imports_cache
|
||||
return rerun_code({
|
||||
...state,
|
||||
external_imports_cache: null,
|
||||
})
|
||||
}
|
||||
|
||||
export const get_initial_state = state => {
|
||||
const with_files = state.project_dir == null
|
||||
? state
|
||||
@@ -798,7 +808,7 @@ export const get_initial_state = state => {
|
||||
|
||||
export const COMMANDS = {
|
||||
input,
|
||||
rerun_code,
|
||||
open_run_window,
|
||||
load_dir,
|
||||
create_file,
|
||||
step_into,
|
||||
|
||||
10
src/effects.js
vendored
10
src/effects.js
vendored
@@ -8,13 +8,21 @@ import {
|
||||
import {FLAGS} from './feature_flags.js'
|
||||
import {exec} from './index.js'
|
||||
|
||||
// Imports in the context of `run_window`, so global variables in loaded
|
||||
// modules refer to that window's context
|
||||
const import_in_run_window = url => {
|
||||
return new globalThis.run_window.Function('url', `
|
||||
return import(url)
|
||||
`)(url)
|
||||
}
|
||||
|
||||
const load_external_imports = async state => {
|
||||
if(state.loading_external_imports_state == null) {
|
||||
return
|
||||
}
|
||||
const urls = state.loading_external_imports_state.external_imports
|
||||
const results = await Promise.allSettled(
|
||||
urls.map(u => import(
|
||||
urls.map(u => import_in_run_window(
|
||||
/^\w+:\/\//.test(u)
|
||||
? // starts with protocol, import as is
|
||||
u
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import {COMMANDS, get_initial_state} from './cmd.js'
|
||||
import {active_frame} from './calltree.js'
|
||||
import {get_initial_state} from './cmd.js'
|
||||
import {UI} from './editor/ui.js'
|
||||
import {EFFECTS, render_initial_state, render_common_side_effects} from './effects.js'
|
||||
import {load_dir} from './filesystem.js'
|
||||
@@ -62,10 +61,13 @@ const read_modules = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
let COMMANDS
|
||||
let ui
|
||||
let state
|
||||
|
||||
export const init = (container) => {
|
||||
export const init = (container, _COMMANDS) => {
|
||||
COMMANDS = _COMMANDS
|
||||
|
||||
set_error_handler(window)
|
||||
|
||||
read_modules().then(initial_state => {
|
||||
|
||||
6
src/launch.js
Normal file
6
src/launch.js
Normal file
@@ -0,0 +1,6 @@
|
||||
// external
|
||||
import {init} from './index.js'
|
||||
|
||||
import {COMMANDS} from './cmd.js'
|
||||
|
||||
init(globalThis.document.getElementById('app'), COMMANDS)
|
||||
Reference in New Issue
Block a user