Update state and append state methods in SharedState and CustomComponent

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-03-01 23:57:28 -03:00
commit 88b2ab328f
2 changed files with 7 additions and 3 deletions

View file

@ -28,7 +28,7 @@ class SharedState(CustomComponent):
self.update_state(name, record)
state = self.get_state(name)
if not isinstance(state, Record):
if state and not isinstance(state, Record):
if isinstance(state, str):
state = Record(text=state)
elif isinstance(state, dict):

View file

@ -76,13 +76,17 @@ class CustomComponent(Component):
def update_state(self, name: str, value: Any):
try:
self.vertex.graph.state_manager.update_state(key=name, new_state=value)
self.vertex.graph.update_state(
name=name, record=value, caller=self.vertex.id
)
except Exception as e:
raise ValueError(f"Error updating state: {e}")
def append_state(self, name: str, value: Any):
try:
self.vertex.graph.state_manager.append_state(key=name, new_state=value)
self.vertex.graph.append_state(
key=name, record=value, caller=self.vertex.id
)
except Exception as e:
raise ValueError(f"Error appending state: {e}")