ecmascript-immutable-data-structures
ecmascript-immutable-data-structures copied to clipboard
New JSON method
There already seems to be a toJSON
method on the prototypes of the immutable types.
There should be a new method of JSON
as well.
JSON.parseImmutable
This would return an immutable values instead of a mutable one.
In case the toImmutable
method is added to the prototypes, this would as simple as this, behind the scenes:
JSON.parseImmutable = (string) => JSON.parse(string).toImmutable()
The actual implementation will be smarter in that it will not throw an error if the JSON value is already immutable (string/number/bool).