Update state and append state methods in SharedState and CustomComponent
This commit is contained in:
parent
3d4ab24858
commit
88b2ab328f
2 changed files with 7 additions and 3 deletions
|
|
@ -28,7 +28,7 @@ class SharedState(CustomComponent):
|
||||||
self.update_state(name, record)
|
self.update_state(name, record)
|
||||||
|
|
||||||
state = self.get_state(name)
|
state = self.get_state(name)
|
||||||
if not isinstance(state, Record):
|
if state and not isinstance(state, Record):
|
||||||
if isinstance(state, str):
|
if isinstance(state, str):
|
||||||
state = Record(text=state)
|
state = Record(text=state)
|
||||||
elif isinstance(state, dict):
|
elif isinstance(state, dict):
|
||||||
|
|
|
||||||
|
|
@ -76,13 +76,17 @@ class CustomComponent(Component):
|
||||||
|
|
||||||
def update_state(self, name: str, value: Any):
|
def update_state(self, name: str, value: Any):
|
||||||
try:
|
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:
|
except Exception as e:
|
||||||
raise ValueError(f"Error updating state: {e}")
|
raise ValueError(f"Error updating state: {e}")
|
||||||
|
|
||||||
def append_state(self, name: str, value: Any):
|
def append_state(self, name: str, value: Any):
|
||||||
try:
|
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:
|
except Exception as e:
|
||||||
raise ValueError(f"Error appending state: {e}")
|
raise ValueError(f"Error appending state: {e}")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue