I am making an application in React Native that stores data with PouchDB. I first created a linked list, which is an object of a class named "LinkedList", which has methods, and stored it in PouchDB. The issue with PouchDB is that it stores data as JSON files, which means that if I tried to recover the linked list in a variable, let's say "myLinkedList", it would be now of type "Object {}" instead of "LinkedList".
Based on an answer from Parse JSON String into a Particular Object Prototype in JavaScript, I managed to solve this using:
Object.setPrototypeOf(myLinkedList, LinkedList.prototype)
and then myLinkedList would be a "LinkedList" object again.
But my current problem comes when I make a "DoubleLinkedList" class. As its name suggests, if a node references a next node, then the next one also references the previous one, which is circular. When I try to store an object of that class in PouchDB, as it creates JSON files, when it has to store the reference to the previous node it does not write a pointer but it puts again all the information of the previous node, which will include again the information of the current node because its reference to the next one, and so on. It causes and infinite loop that is making my app to crash. And I suspect that it would crash with any graph that has a cycle.
How can I solve this problem?