mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-14 05:14:28 -08:00
async calls WIP
This commit is contained in:
@@ -447,10 +447,15 @@ nodes that are in the second tree that are not in the first tree
|
||||
*/
|
||||
const merge_calltrees = (prev, next) => {
|
||||
return Object.fromEntries(
|
||||
Object.entries(prev).map(([module, {exports, calls}]) =>
|
||||
Object.entries(prev).map(([module, {is_external, exports, calls}]) =>
|
||||
[
|
||||
module,
|
||||
{exports, calls: merge_calltree_nodes(calls, next[module].calls)[1]}
|
||||
is_external
|
||||
? {is_external, exports}
|
||||
: {
|
||||
exports,
|
||||
calls: merge_calltree_nodes(calls, next[module].calls)[1]
|
||||
}
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
@@ -71,6 +71,7 @@ const run_code = (s, index, dirty_files) => {
|
||||
...s,
|
||||
parse_result,
|
||||
calltree: null,
|
||||
async_calls: null,
|
||||
|
||||
// Shows that calltree is brand new and requires entire rerender
|
||||
calltree_changed_token: {},
|
||||
@@ -82,7 +83,6 @@ const run_code = (s, index, dirty_files) => {
|
||||
calltree_node_is_expanded: null,
|
||||
frames: null,
|
||||
calltree_node_by_loc: null,
|
||||
// TODO keep selection_state?
|
||||
selection_state: null,
|
||||
loading_external_imports_state: null,
|
||||
}
|
||||
@@ -734,8 +734,10 @@ const move_cursor = (s, index) => {
|
||||
return do_move_cursor(state, index)
|
||||
}
|
||||
|
||||
const on_async_call = (state, ...args) => {
|
||||
console.log('on_async_call', state, args)
|
||||
const on_async_call = (state, call) => {
|
||||
return {...state,
|
||||
async_calls: [...(state.async_calls ?? []), call]
|
||||
}
|
||||
}
|
||||
|
||||
const load_dir = (state, dir) => {
|
||||
|
||||
15
src/eval.js
15
src/eval.js
@@ -391,7 +391,12 @@ export const eval_modules = (
|
||||
is_toplevel_call = is_toplevel_call_copy
|
||||
|
||||
if(is_recording_async_calls && is_toplevel_call) {
|
||||
on_async_call(children)
|
||||
if(children.length != 1) {
|
||||
throw new Error('illegal state')
|
||||
}
|
||||
const call = children[0]
|
||||
children = null
|
||||
on_async_call(call)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -542,13 +547,7 @@ export const eval_modules = (
|
||||
,
|
||||
|
||||
/* on_async_call */
|
||||
calls => {
|
||||
on_async_call(
|
||||
calls.map(c =>
|
||||
assign_code(modules, c)
|
||||
)
|
||||
)
|
||||
},
|
||||
call => on_async_call(assign_code(modules, call))
|
||||
)
|
||||
|
||||
const calltree_actions = {
|
||||
|
||||
11
src/index.js
11
src/index.js
@@ -10,6 +10,17 @@ const EXAMPLE = `const fib = n =>
|
||||
: fib(n - 1) + fib(n - 2)
|
||||
fib(6)`
|
||||
|
||||
|
||||
// By default run code in hidden iframe, until user explicitly opens visible
|
||||
// window
|
||||
globalThis.run_window = (() => {
|
||||
const iframe = document.createElement('iframe')
|
||||
iframe.src = 'about:blank'
|
||||
iframe.setAttribute('hidden', '')
|
||||
document.body.appendChild(iframe)
|
||||
return iframe.contentWindow
|
||||
})()
|
||||
|
||||
export const open_run_window = () => {
|
||||
if(globalThis.run_window != null) {
|
||||
globalThis.run_window.close()
|
||||
|
||||
Reference in New Issue
Block a user