Skip to content

Commit

Permalink
fix: json.dumps for dicts instead of casting to str
Browse files Browse the repository at this point in the history
  • Loading branch information
mmikita95 committed Mar 12, 2024
1 parent 34f63c1 commit 796a17c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 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 @@ -78,7 +84,7 @@ def _create_component(

# Converting all passed content values to strings
raw_content = kwargs.pop("content", {})
content = {key: str(value) for key, value in raw_content.items()}
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)
Expand Down

0 comments on commit 796a17c

Please sign in to comment.