mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 21:14:28 -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'
|
const collect_files = dir => dir.kind == 'file'
|
||||||
? [dir]
|
? [dir]
|
||||||
: dir.children.map(collect_files).flat()
|
: dir.children.map(collect_files).flat()
|
||||||
@@ -763,13 +763,21 @@ const load_dir = (state, dir) => {
|
|||||||
collect_files(dir).map(f => [f.path, f.contents])
|
collect_files(dir).map(f => [f.path, f.contents])
|
||||||
)
|
)
|
||||||
|
|
||||||
// Clear parse cache and rerun code
|
return {
|
||||||
return rerun_code({
|
|
||||||
...state,
|
...state,
|
||||||
// remove cache
|
|
||||||
parse_result: null,
|
|
||||||
project_dir: dir,
|
project_dir: dir,
|
||||||
files: {...files, ...state.files},
|
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 get_initial_state = state => {
|
||||||
const with_files = state.project_dir == null
|
const with_files = state.project_dir == null
|
||||||
? state
|
? state
|
||||||
: load_dir(state, state.project_dir)
|
: do_load_dir(state, state.project_dir)
|
||||||
|
|
||||||
const entrypoint = with_files.entrypoint
|
const entrypoint = with_files.entrypoint
|
||||||
const current_module = with_files.current_module
|
const current_module = with_files.current_module
|
||||||
|
const html_file = with_files.html_file
|
||||||
|
|
||||||
const s = {
|
return {
|
||||||
...with_files,
|
...with_files,
|
||||||
// If module for entrypoint or current_module does not exist, use *scratch*
|
// If module for entrypoint or current_module does not exist, use *scratch*
|
||||||
entrypoint:
|
entrypoint:
|
||||||
@@ -804,9 +813,10 @@ const get_initial_state = state => {
|
|||||||
current_module: with_files.files[current_module] == null
|
current_module: with_files.files[current_module] == null
|
||||||
? ''
|
? ''
|
||||||
: current_module,
|
: current_module,
|
||||||
|
html_file: with_files.files[html_file] == null
|
||||||
|
? ''
|
||||||
|
: html_file,
|
||||||
}
|
}
|
||||||
|
|
||||||
return run_code(s, 0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const COMMANDS = {
|
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) => {
|
export const render_initial_state = (ui, state) => {
|
||||||
ensure_session(ui, state)
|
ensure_session(ui, state)
|
||||||
ui.editor.switch_session(state.current_module)
|
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) => {
|
export const render_common_side_effects = (prev, next, command, ui) => {
|
||||||
|
|||||||
@@ -58,8 +58,8 @@ type Node = ToplevelCall | Call
|
|||||||
|
|
||||||
// TODO just export const Iframe_Function?
|
// TODO just export const Iframe_Function?
|
||||||
const make_function = (...args) => {
|
const make_function = (...args) => {
|
||||||
if(globalThis.run_window == null) {
|
if(globalThis.process != null) {
|
||||||
// Tests are run in Node.js or user have not opened run_window
|
// Tests are run in Node.js
|
||||||
return new Function(...args)
|
return new Function(...args)
|
||||||
} else {
|
} else {
|
||||||
// Code run in browser and user opened run_window
|
// 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 => {
|
read_modules().then(initial_state => {
|
||||||
|
|
||||||
open_run_iframe(initial_state)
|
|
||||||
|
|
||||||
state = COMMANDS.get_initial_state({
|
state = COMMANDS.get_initial_state({
|
||||||
...initial_state,
|
...initial_state,
|
||||||
on_async_call: (...args) => exec('on_async_call', ...args)
|
on_async_call: (...args) => exec('on_async_call', ...args)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Expose state for debugging
|
// Expose state for debugging
|
||||||
globalThis.__state = state
|
globalThis.__state = state
|
||||||
ui = new UI(container, state)
|
ui = new UI(container, state)
|
||||||
// Expose for debugging
|
// Expose for debugging
|
||||||
globalThis.__ui = ui
|
globalThis.__ui = ui
|
||||||
|
|
||||||
render_initial_state(ui, state)
|
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
|
// Sanity check
|
||||||
if(state?.parse_result == null) {
|
if(state?.current_module == null) {
|
||||||
console.error('command did not return state, returned', result)
|
console.error('command did not return state, returned', result)
|
||||||
throw new Error('illegal state')
|
throw new Error('illegal state')
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user