Skip to content

Commit

Permalink
Merge pull request writer#303 from mmikita95/fix-content-str-cast
Browse files Browse the repository at this point in the history
  • Loading branch information
ramedina86 authored Mar 12, 2024
2 parents 1bce212 + 796a17c commit 8d3801a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/streamsync/ui_manager.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from json import dumps as json_dumps
from typing import Optional, Union

from streamsync.core import base_component_tree
from streamsync.core_ui import (Component, SessionComponentTree,
UIError, current_parent_container)
from streamsync.core_ui import (Component, SessionComponentTree, UIError,
current_parent_container)


class StreamsyncUI:
Expand Down Expand Up @@ -57,6 +58,11 @@ def _prepare_binding(self, raw_binding):
# TODO
return raw_binding

def _prepare_value(self, value):
if isinstance(value, dict):
return json_dumps(value)
return str(value)

def _create_component(
self,
component_type: str,
Expand All @@ -76,6 +82,10 @@ def _create_component(
else:
parent_id = "root" if not parent_container else parent_container.id

# Converting all passed content values to strings
raw_content = kwargs.pop("content", {})
content = {key: self._prepare_value(value) for key, value in raw_content.items()}

position: Optional[int] = kwargs.pop("position", None)
is_positionless: bool = kwargs.pop("positionless", False)
raw_handlers: dict = kwargs.pop("handlers", {})
Expand All @@ -88,6 +98,7 @@ def _create_component(
type=component_type,
parentId=parent_id,
flag="cmc",
content=content,
handlers=handlers,
binding=binding,
**kwargs
Expand Down

0 comments on commit 8d3801a

Please sign in to comment.