Skip to content

Commit

Permalink
fix: updates per review
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
mmikita95 committed Feb 27, 2024
1 parent e74c8b6 commit dd5c43b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
16 changes: 8 additions & 8 deletions src/streamsync/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
15 changes: 8 additions & 7 deletions ui/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export function generateCore() {
});
}

function updateComponents(newComponents: Record<string, any>) {
function ingestComponents(newComponents: Record<string, any>) {
if (!newComponents) return;
components.value = newComponents
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -436,19 +436,20 @@ export function generateCore() {
*/
async function sendComponentUpdate(): Promise<void> {
/*
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) => {
Expand Down

0 comments on commit dd5c43b

Please sign in to comment.