Skip to content
This repository was archived by the owner on Apr 15, 2025. It is now read-only.

Commit 3331d6e

Browse files
authored
replace JSON.parseImmutable with links to seperate proposal (#341)
1 parent c57bf32 commit 3331d6e

File tree

4 files changed

+13
-190
lines changed

4 files changed

+13
-190
lines changed

README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,7 @@ JSON.stringify(#[true, #{ a: #[1, 2, 3] }]); // '[true,{"a":[1,2,3]}]'
444444

445445
## JSON.parseImmutable
446446

447-
We propose to add `JSON.parseImmutable` so we can extract a Record/Tuple type out of a JSON string instead of an Object/Array.
448-
449-
The signature of `JSON.parseImmutable` is identical to `JSON.parse` with the only change being in the return type that is now a Record or a Tuple.
447+
Please see https://github.com/tc39/proposal-json-parseimmutable
450448

451449
## `Tuple.prototype`
452450

cookbook/en.md

+12-7
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,7 @@ console.log(a === c); // false
168168

169169
### Parse
170170

171-
```js
172-
const user = JSON.parseImmutable('{ "name": "danny", "admin": false, "score": 42 }');
173-
console.log(user === #{ name: "danny", admin: false, score: 42 });
174-
```
171+
Please see https://github.com/tc39/proposal-json-parseimmutable
175172

176173
> Note: at the time of writing this, the playground does not support `JSON.parseImmutable`.
177174
@@ -186,7 +183,17 @@ console.log(jsonUser); // {"admin":false,"name":"danny","score":42}
186183

187184
```js
188185
function recursiveRT(thing) {
189-
return JSON.parseImmutable(JSON.stringify(thing));
186+
function reviver(value) {
187+
if (typeof value === 'object' && value !== null) {
188+
if (Array.isArray(value)) {
189+
return Tuple.from(value);
190+
} else {
191+
return Record(value);
192+
}
193+
}
194+
return value;
195+
}
196+
return JSON.parse(JSON.stringify(thing), reviver);
190197
}
191198

192199
const user = { name: "danny", stats: {
@@ -200,8 +207,6 @@ console.log(fixedUser === #{ name: "danny", stats: #{
200207
} }); // true
201208
```
202209

203-
> Note: at the time of writing this, the playground does not support `JSON.parseImmutable`.
204-
205210
## Array-like manipulations with Tuple by copy
206211

207212
Using spread operations, `toReversed()`, `toSorted()`, `toSpliced()` or `with()` methods you can mutate tuples by copy:

spec.html

-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,4 @@
1515
<emu-import href="spec/expression.html"></emu-import>
1616
<emu-import href="spec/immutable-data-structures.html"></emu-import>
1717
<emu-import href="spec/fundamental-objects.html"></emu-import>
18-
<emu-import href="spec/structured-data.html"></emu-import>
1918
<emu-import href="spec/purely-editorial.html"></emu-import>

spec/structured-data.html

-179
This file was deleted.

0 commit comments

Comments
 (0)