dynamic-object
dynamic-object copied to clipboard
Make mutating operations on wrapped maps work
Currently, wrapped maps use the passed-in Map as-is. This produces intuitive results when the Map is mutated, but as soon as you try to modify the DynamicObject, you get cryptic errors due to attempts to use this Map as an IPersistentMap or IObj (in the case of metadata operations).
This change introduces a wrapper which proxies non-mutating calls through to the underlying map directly, but which creates a copy of the map (as a PersistentHashMap) if mutating operations are performed.
I considered simply having wrap() copy the map directly, but I felt that the name 'wrap' would be seen to imply that mutations on the underlying map would be reflected in the wrapped DynamicObject, so I chose this route instead.