Document Layers with Undo
Asked at Figma· Screen
Reported by the problem's creator, not verified
A design document is a set of layers. Each layer has an integer id and holds named properties such as color or width, each with a string value.
A layer exists only while it has at least one property. Reading a layer that has none returns None, whether it was never touched or all of its properties were undone.
You build the Document class behind an editor's undo history in three stages. Each example drives one Document instance through a list of [method, [args]] calls and lists every call's return value.
Examples
Example 1
Input: init =
[], operations =[["apply",[1,"color","green"]],["apply",[2,"shape","triangle"]],["apply",[1,"color","blue"]],["get_layer",[1]],["undo",[]],["get_layer",[1]],["get_layer",[2]],["undo",[]],["undo",[]],["get_layer",[2]],["get_layer",[1]],["undo",[]]]Output:
[null,null,null,[["color","blue"]],true,[["color","green"]],[["shape","triangle"]],true,true,null,null,false]Explanation: The third apply overwrites layer 1's color, so the first undo restores
green. The next two undos remove layer 2'sshapeand layer 1'scolor, leaving both layers without properties, so reading them returnsNone. The last undo has nothing left to revert and returnsFalse.