From 4f1f6c2f7e50c0cd3616984c7d615ee1b156dfdb Mon Sep 17 00:00:00 2001 From: Dmitry Vasilev Date: Wed, 16 Nov 2022 12:33:32 +0800 Subject: [PATCH] refactor async_calls WIP --- src/calltree.js | 29 +++++++++++++---------------- src/cmd.js | 10 +++++++--- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/calltree.js b/src/calltree.js index 8326a81..79b22c1 100644 --- a/src/calltree.js +++ b/src/calltree.js @@ -13,18 +13,6 @@ export const pp_calltree = tree => ({ children: tree.children && tree.children.map(pp_calltree) }) -const find_calltree_node = (state, id) => { - return find_node( - { - children: [ - root_calltree_node(state), - {children: state.async_calls}, - ] - }, - n => n.id == id - ) -} - const is_stackoverflow = node => // Chrome node.error.message == 'Maximum call stack size exceeded' @@ -36,6 +24,8 @@ export const calltree_node_loc = node => node.toplevel ? {module: node.module} : node.fn.__location +export const get_async_calls = state => state.calltree.children[1].children + export const root_calltree_node = state => // Returns calltree node for toplevel // It is either toplevel for entrypoint module, or for module that throw @@ -46,6 +36,14 @@ export const root_calltree_node = state => export const root_calltree_module = state => root_calltree_node(state).module +export const make_calltree = (root_calltree_node, async_calls) => ({ + id: 'calltree', + children: [ + root_calltree_node, + {id: 'async_calls', children: async_calls}, + ] +}) + export const is_native_fn = calltree_node => !calltree_node.toplevel && calltree_node.fn.__location == null @@ -463,7 +461,7 @@ export const toggle_expanded = (state, is_exp) => { } const click = (state, id) => { - const node = find_calltree_node(state, id) + const node = find_node(state.calltree, n => n.id == id) const {state: nextstate, effects} = jump_calltree_node(state, node) if(is_expandable(node)) { // `effects` are intentionally discarded, correct `set_caret_position` will @@ -811,9 +809,8 @@ const navigate_logs_increment = (state, increment) => { } const navigate_logs_position = (state, log_position) => { - const node = find_calltree_node( - state, - state.logs.logs[log_position].id + const node = find_node(state.calltree, n => + n.id == state.logs.logs[log_position].id ) const {state: next, effects} = select_arguments( expand_path(jump_calltree_node(state, node).state, node), diff --git a/src/cmd.js b/src/cmd.js index 55f2c4b..b918136 100644 --- a/src/cmd.js +++ b/src/cmd.js @@ -9,7 +9,9 @@ import {load_modules} from './parse_js.js' import {find_export} from './find_definitions.js' import {eval_modules} from './eval.js' import { - root_calltree_node, root_calltree_module, calltree_commands, + root_calltree_node, root_calltree_module, make_calltree, + get_async_calls, + calltree_commands, add_frame, calltree_node_loc, expand_path, initial_calltree_node, default_expand_path, toggle_expanded, active_frame, find_call, find_call_node, set_active_calltree_node @@ -69,7 +71,6 @@ const run_code = (s, index, dirty_files) => { parse_result, calltree: null, modules: null, - async_calls: null, // Shows that calltree is brand new and requires entire rerender calltree_changed_token: {}, @@ -736,7 +737,10 @@ const move_cursor = (s, index) => { const on_async_call = (state, call) => { return {...state, - async_calls: [...(state.async_calls ?? []), call], + calltree: make_calltree( + root_calltree_node(state), + [...(get_async_calls(state) ?? []), call], + ), logs: {...state.logs, logs: state.logs.logs.concat(collect_logs(call))}, } }