From 9c641f759fa550a1e7a783fb89d77ed138ad8938 Mon Sep 17 00:00:00 2001 From: Dmitry Vasilev Date: Wed, 16 Nov 2022 14:01:56 +0800 Subject: [PATCH] refactor async_calls WIP: rerender calltree --- src/editor/calltree.js | 19 +++++++++++-------- src/effects.js | 10 ++++++---- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/editor/calltree.js b/src/editor/calltree.js index e01e0f4..6e85bbf 100644 --- a/src/editor/calltree.js +++ b/src/editor/calltree.js @@ -3,7 +3,7 @@ import {el, stringify, fn_link, scrollIntoViewIfNeeded} from './domutils.js' import {FLAGS} from '../feature_flags.js' import {stringify_for_header} from './value_explorer.js' import {find_node} from '../ast_utils.js' -import {is_expandable, root_calltree_node} from '../calltree.js' +import {is_expandable, root_calltree_node, get_async_calls} from '../calltree.js' // TODO perf - quadratic difficulty const join = arr => arr.reduce( @@ -170,20 +170,23 @@ export class CallTree { root_calltree_node(state), ) - if(prev_state.async_calls != null) { + const prev_async_calls = get_async_calls(prev_state) + const async_calls = get_async_calls(state) + + if(prev_async_calls != null) { // Expand already existing async calls - for(let i = 0; i < prev_state.async_calls.length; i++) { + for(let i = 0; i < prev_async_calls.length; i++) { this.do_render_expand_node( prev_state.calltree_node_is_expanded, state.calltree_node_is_expanded, - prev_state.async_calls[i], - state.async_calls[i], + prev_async_calls[i], + async_calls[i], ) } // Add new async calls - for(let i = prev_state.async_calls.length; i < state.async_calls.length; i++) { + for(let i = prev_async_calls.length; i < async_calls.length; i++) { this.async_calls_root.appendChild( - this.render_node(state.async_calls[i]) + this.render_node(async_calls[i]) ) } } @@ -231,7 +234,7 @@ export class CallTree { el('div', 'call_el', el('i', '', 'async calls'), this.async_calls_root = el('div', 'callnode', - state.async_calls.map(call => this.render_node(call)) + get_async_calls(state).map(call => this.render_node(call)) ) ) ) diff --git a/src/effects.js b/src/effects.js index a2983e1..d8fc228 100644 --- a/src/effects.js +++ b/src/effects.js @@ -1,6 +1,10 @@ import {write_file} from './filesystem.js' import {color_file} from './color.js' -import {root_calltree_node, calltree_node_loc} from './calltree.js' +import { + root_calltree_node, + calltree_node_loc, + get_async_calls +} from './calltree.js' import {FLAGS} from './feature_flags.js' import {exec} from './index.js' @@ -173,7 +177,7 @@ export const render_common_side_effects = (prev, next, command, ui) => { ui.editor.unembed_value_explorer() } else { - if(prev.async_calls == null && next.async_calls != null) { + if(get_async_calls(prev) == null && get_async_calls(next) != null) { ui.calltree.render_async_calls(next) } @@ -181,8 +185,6 @@ export const render_common_side_effects = (prev, next, command, ui) => { prev.calltree != next.calltree || prev.calltree_node_is_expanded != next.calltree_node_is_expanded - || - prev.async_calls != next.async_calls ) { ui.calltree.render_expand_node(prev, next) }