From dd5c43b3d0d1e84e0ac9c97aa7ae127319367916 Mon Sep 17 00:00:00 2001 From: mmikita95 Date: Tue, 27 Feb 2024 09:46:04 +0300 Subject: [PATCH] fix: updates per review - Renames updateComponents to ingestComponents in ui/core/index.ts - Updates comment and variable name for sendComponent Update - Refactors to_dict method of SessionComponentTree in core.py for readability --- src/streamsync/core.py | 16 ++++++++-------- ui/src/core/index.ts | 15 ++++++++------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/streamsync/core.py b/src/streamsync/core.py index 214c56a1a..6cdd8488f 100644 --- a/src/streamsync/core.py +++ b/src/streamsync/core.py @@ -585,19 +585,19 @@ def get_component(self, component_id: str) -> Optional[Component]: if session_component_present: return session_component - - return self.base_component_tree.get_component(component_id) - + return self.base_component_tree.get_component(component_id) def to_dict(self) -> Dict: active_components = { - k: v.to_dict() - for k, v in self.base_component_tree.components.items() - } - for id, component in {**self.components}.items(): + # Collecting serialized base tree components + component_id: base_component.to_dict() + for component_id, base_component + in self.base_component_tree.components.items() + } + for component_id, session_component in self.components.items(): # Overriding base tree components with session-specific ones - active_components[id] = component.to_dict() + active_components[component_id] = session_component.to_dict() return active_components diff --git a/ui/src/core/index.ts b/ui/src/core/index.ts index 1440ddc44..2b011c3d6 100644 --- a/ui/src/core/index.ts +++ b/ui/src/core/index.ts @@ -158,7 +158,7 @@ export function generateCore() { }); } - function updateComponents(newComponents: Record) { + function ingestComponents(newComponents: Record) { if (!newComponents) return; components.value = newComponents } @@ -203,7 +203,7 @@ export function generateCore() { ) { ingestMutations(message.payload?.mutations); collateMail(message.payload?.mail); - updateComponents(message.payload?.components); + ingestComponents(message.payload?.components); } const mapItem = frontendMessageMap.value.get(message.trackingId); @@ -436,19 +436,20 @@ export function generateCore() { */ async function sendComponentUpdate(): Promise { /* - Only send components created by the frontend (static), to avoid re-feeding the backend - those components created by the backend. + Ensure that the backend receives only components + created by the frontend (Builder-managed components, BMC), + and not the components it generated (Code-managed components, CMC). */ - const staticComponents = {}; + const builderManagedComponents = {}; Object.entries(components.value).forEach(([componentId, component]) => { if (component.flag === 'cmc') return; - staticComponents[componentId] = component; + builderManagedComponents[componentId] = component; }); const payload = { - components: staticComponents, + components: builderManagedComponents, }; return new Promise((resolve, reject) => {