I haven’t tried but, but are you sure that you can store functions in ionic storage? It says: Storage is an easy way to store key/value pairs and JSON objects. JSON Objects have no functions.
You could implement a class with a toJSON method to extract the state from the object for storing and also implement a fromJSON static method for that class, that restores that object.
Oh yeah I just realize that you are probably right! Is there no way to store class-objects in Ionic? This would make things a lot easier. I find it - compared to other programming languages - also quite complicated to share data and methods between pages, which would allow to store i.e. simply an index and recover from any page an object from an array by using this global index. But to share that array and the corresponding method is… puh.
Or is there a simpler and more intelligent way to handle data (objects) that must be stored and be available over multiple pages?
Maybe my naming was bad. I only map the class objects to simple data structures, that are json valid to transfer them for example with a rest api. I do not use JSON.parse and JSON.stringify. I don’t know if ionic storage uses it internally, but I would assume it. I don’t know a way of storing js objects without converting them to json or string.
Well you don’t need to do either one, with the Firestore database being the example that’s maybe most interesting to Ionic programming. (Though maybe Firestore stringifies under the hood? I’m not sure…) But I really like the code you’ve posted, so I wasn’t talking about any approach you’ve been taking.
But let’s suppose that for whatever reason you need to parse to JSON before doing operation X. If you have to do it anyway, I’d suggest you look at offloading Operation X to a web worker.