introduce
Generate immutable data structures, which are more efficient than deep copy (only the changed parts and their parent nodes are changed, and the unchanged parts are kept as references)
use
immerjs.github.io/immer/
Sequence diagram
,
knowledge
- Proxy.revocable
- The proxy.revocable () method can be used to create a revocable Proxy object. The return value of this method is an object of the structure {“proxy”: proxy, “REVOKE “: Revoke} REVOKE is a revoke method that, once a proxy object has been revoked, makes it almost completely unavailable, and any proxyable operation performed on it raises TypeError
- const vs Object.freeze
- Const: A variable cannot be changed, but its value can be changed
- Object.freeze Freezes an Object, ignoring any external changes to the Object
const alligator = { canItFly : false }; Object.freeze(alligator); alligator.canItFly = true; // Alligator = {PI: 3}; // This will throw an TypeErrorCopy the code