mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 13:04:30 -08:00
fix
This commit is contained in:
28
src/cmd.js
28
src/cmd.js
@@ -754,7 +754,7 @@ const on_async_call = (state, call) => {
|
||||
}
|
||||
}
|
||||
|
||||
const load_dir = (state, dir) => {
|
||||
const do_load_dir = (state, dir) => {
|
||||
const collect_files = dir => dir.kind == 'file'
|
||||
? [dir]
|
||||
: dir.children.map(collect_files).flat()
|
||||
@@ -763,13 +763,21 @@ const load_dir = (state, dir) => {
|
||||
collect_files(dir).map(f => [f.path, f.contents])
|
||||
)
|
||||
|
||||
// Clear parse cache and rerun code
|
||||
return rerun_code({
|
||||
return {
|
||||
...state,
|
||||
// remove cache
|
||||
parse_result: null,
|
||||
project_dir: dir,
|
||||
files: {...files, ...state.files},
|
||||
}
|
||||
}
|
||||
|
||||
const load_dir = (state, dir) => {
|
||||
// Clear parse cache and rerun code
|
||||
return rerun_code({
|
||||
...do_load_dir(state, dir),
|
||||
// remove cache. We have to clear cache because imports of modules that are
|
||||
// not available because project_dir is not available have errors and the
|
||||
// errors are cached
|
||||
parse_result: null,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -789,12 +797,13 @@ const open_run_window = state => {
|
||||
const get_initial_state = state => {
|
||||
const with_files = state.project_dir == null
|
||||
? state
|
||||
: load_dir(state, state.project_dir)
|
||||
: do_load_dir(state, state.project_dir)
|
||||
|
||||
const entrypoint = with_files.entrypoint
|
||||
const current_module = with_files.current_module
|
||||
const html_file = with_files.html_file
|
||||
|
||||
const s = {
|
||||
return {
|
||||
...with_files,
|
||||
// If module for entrypoint or current_module does not exist, use *scratch*
|
||||
entrypoint:
|
||||
@@ -804,9 +813,10 @@ const get_initial_state = state => {
|
||||
current_module: with_files.files[current_module] == null
|
||||
? ''
|
||||
: current_module,
|
||||
html_file: with_files.files[html_file] == null
|
||||
? ''
|
||||
: html_file,
|
||||
}
|
||||
|
||||
return run_code(s, 0)
|
||||
}
|
||||
|
||||
export const COMMANDS = {
|
||||
|
||||
6
src/effects.js
vendored
6
src/effects.js
vendored
@@ -122,12 +122,6 @@ const render_parse_result = (ui, state) => {
|
||||
export const render_initial_state = (ui, state) => {
|
||||
ensure_session(ui, state)
|
||||
ui.editor.switch_session(state.current_module)
|
||||
render_parse_result(ui, state)
|
||||
if(state.current_calltree_node != null) {
|
||||
ui.render_debugger(state)
|
||||
render_coloring(ui, state)
|
||||
}
|
||||
load_external_imports(state)
|
||||
}
|
||||
|
||||
export const render_common_side_effects = (prev, next, command, ui) => {
|
||||
|
||||
@@ -58,8 +58,8 @@ type Node = ToplevelCall | Call
|
||||
|
||||
// TODO just export const Iframe_Function?
|
||||
const make_function = (...args) => {
|
||||
if(globalThis.run_window == null) {
|
||||
// Tests are run in Node.js or user have not opened run_window
|
||||
if(globalThis.process != null) {
|
||||
// Tests are run in Node.js
|
||||
return new Function(...args)
|
||||
} else {
|
||||
// Code run in browser and user opened run_window
|
||||
|
||||
11
src/index.js
11
src/index.js
@@ -141,18 +141,23 @@ export const init = (container, _COMMANDS) => {
|
||||
|
||||
read_modules().then(initial_state => {
|
||||
|
||||
open_run_iframe(initial_state)
|
||||
|
||||
state = COMMANDS.get_initial_state({
|
||||
...initial_state,
|
||||
on_async_call: (...args) => exec('on_async_call', ...args)
|
||||
})
|
||||
|
||||
// Expose state for debugging
|
||||
globalThis.__state = state
|
||||
ui = new UI(container, state)
|
||||
// Expose for debugging
|
||||
globalThis.__ui = ui
|
||||
|
||||
render_initial_state(ui, state)
|
||||
|
||||
open_run_iframe(state)
|
||||
|
||||
// TODO exec on iframe load
|
||||
exec('open_run_window')
|
||||
})
|
||||
}
|
||||
|
||||
@@ -186,7 +191,7 @@ export const exec = (cmd, ...args) => {
|
||||
}
|
||||
|
||||
// Sanity check
|
||||
if(state?.parse_result == null) {
|
||||
if(state?.current_module == null) {
|
||||
console.error('command did not return state, returned', result)
|
||||
throw new Error('illegal state')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user