Restructure frontend TS files so managers/stores export destructors instead of returning them from their constructors (#3919)

* Replace parameter passing with getContext and extract destroy functions to module-level exports

* Resend layouts from Rust when editor is re-mounted on HMR

* Code review
This commit is contained in:
Keavon Chambers
2026-03-19 18:25:34 -07:00
committed by GitHub
parent 124b17f609
commit 2e2c4fe180
21 changed files with 986 additions and 900 deletions

View File

@@ -8,6 +8,7 @@ pub enum LayoutMessage {
layout_target: LayoutTarget,
widget_id: WidgetId,
},
ResendAllLayouts,
SendLayout {
layout: Layout,
layout_target: LayoutTarget,

View File

@@ -33,6 +33,20 @@ impl MessageHandler<LayoutMessage, LayoutMessageContext<'_>> for LayoutMessageHa
// Resend that diff
self.send_diff(vec![diff], layout_target, responses, action_input_mapping);
}
LayoutMessage::ResendAllLayouts => {
// Collect non-empty layouts and their indices, then clear the stored copies so diffs compute as full re-sends
let layouts_to_resend: Vec<_> = self
.layouts
.iter_mut()
.enumerate()
.filter(|(_, layout)| !layout.0.is_empty())
.map(|(i, layout)| (LayoutTarget::from(i as u8), std::mem::take(layout)))
.collect();
for (layout_target, layout) in layouts_to_resend {
self.diff_and_send_layout_to_frontend(layout_target, layout, responses, action_input_mapping);
}
}
LayoutMessage::SendLayout { layout, layout_target } => {
self.diff_and_send_layout_to_frontend(layout_target, layout, responses, action_input_mapping);
}

View File

@@ -20,10 +20,30 @@ impl core::fmt::Display for WidgetId {
}
}
#[cfg_attr(feature = "wasm", derive(tsify::Tsify))]
#[derive(PartialEq, Clone, Debug, Hash, Eq, Copy, serde::Serialize, serde::Deserialize)]
#[repr(u8)]
pub enum LayoutTarget {
macro_rules! define_layout_target {
($($(#[$attr:meta])* $variant:ident),* $(,)?) => {
#[cfg_attr(feature = "wasm", derive(tsify::Tsify))]
#[derive(PartialEq, Clone, Debug, Hash, Eq, Copy, serde::Serialize, serde::Deserialize)]
#[repr(u8)]
pub enum LayoutTarget {
$($(#[$attr])* $variant,)*
// KEEP THIS ENUM LAST
// This is a marker that is used to define an array that is used to hold widgets
#[serde(skip)]
_LayoutTargetLength,
}
impl From<u8> for LayoutTarget {
fn from(value: u8) -> Self {
match value {
$(x if x == Self::$variant as u8 => Self::$variant,)*
_ => panic!("Invalid LayoutTarget discriminant: {value}"),
}
}
}
};
}
define_layout_target!(
/// The spreadsheet panel allows for the visualisation of data in the graph.
DataPanel,
/// Contains the action buttons at the bottom of the dialog. Must be shown with the `FrontendMessage::DisplayDialog` message.
@@ -58,12 +78,7 @@ pub enum LayoutTarget {
WelcomeScreenButtons,
/// The color swatch for the working colors and a flip and reset button found at the bottom of the tool shelf.
WorkingColors,
// KEEP THIS ENUM LAST
// This is a marker that is used to define an array that is used to hold widgets
#[serde(skip)]
_LayoutTargetLength,
}
);
/// For use by structs that define a UI widget layout by implementing the layout() function belonging to this trait.
/// The send_layout() function can then be called by other code which is a part of the same struct so as to send the layout to the frontend.