I don't think they do though?
I don't think they do though?
let obj = { id: 1 }
for (let id = 2; id <= 10; id++) {
obj = { id, previous: JSON.stringify(obj) }
} let obj = { id: 1 }
for (let id = 2; id <= 10; id++) {
obj = { id, previous: obj }
}If this sounds like a cons cell, that’s what it is! It’s also a linked list. The laziness they want to achieve (only de/serialize one screen at a time per navigation forward or back) is also straightforward.
- forward: serialize the current screen, trim the leading/trailing quote off the previous serialization, insert with a comma before the new trailing bracket
- back: parse history, head is your desired “previous” screen, tail is your now-“previous” screen’s history
There’s a tiny amount of overhead to this approach, but not nearly as much as repeatedly reserializing the same string to shoehorn it into a serialized structure that doesn’t let you cheat a little bit with well known start/end characters.