Refine change set

This commit is contained in:
wqy
2022-09-17 23:43:03 +08:00
parent 36a8fa2f79
commit fc0283b417
5 changed files with 246 additions and 209 deletions

View File

@@ -1,14 +1,12 @@
class ChangeSet:
def __init__(self) -> None:
self.added : list[dict[str, str]] = []
self.deleted : list[dict[str, str]] = []
self.updated : list[dict[str, str]] = []
self.operations : list[dict[str, str]] = []
def add(self, type: str, id: str) -> None:
self.added.append({ 'type': type, 'id': id })
self.operations.append({ 'operation': 'add', 'type': type, 'id': id })
def delete(self, type: str, id: str) -> None:
self.deleted.append({ 'type': type, 'id': id })
self.operations.append({ 'operation': 'delete', 'type': type, 'id': id })
def update(self, type: str, id: str, property_name: str, property_type: str, property_value: str) -> None:
self.updated.append({ 'type': type, 'id': id, 'property': property_name, 'property_type': property_type, 'property_value': property_value })
def update(self, type: str, id: str, property: str) -> None:
self.operations.append({ 'operation': 'update', 'type': type, 'id': id, 'property': property })

View File

@@ -20,5 +20,5 @@ def set_title(name: str, value: str) -> ChangeSet:
add_operation(name, redo, undo)
change = ChangeSet()
change.update('title', 'null', 'value', 'str', value)
change.update('title', 'null', 'value')
return change

View File

@@ -39,5 +39,5 @@ def set_node_coord(name: str, node_type: str, id: str, x: float, y: float) -> Ch
add_operation(name, redo, undo)
change = ChangeSet()
change.update(node_type, id, 'coord', 'point', str({'x': x, 'y': y}))
change.update(node_type, id, 'coord')
return change

View File

@@ -30,5 +30,5 @@ def update(name: str, type: str, table: str, id_key: str, id_value: str, key: st
add_operation(name, redo, undo)
change = ChangeSet()
change.update(type, id_value, key, key_type, value)
change.update(type, id_value, key)
return change