Since I need offline functionality in my Ionic 2 app and dealing with lots of data, I heavily rely on Storage.
I used to put my objects in maps like
public hashtags:Map<any,Hashtag> = new Map<any,Hashtag>();
...
this.hashtags.set(hashtag.id,hashtag)
stored it like
this.storage.set("hashtags",this.hashtags).then(()=>{
console.log("stored hashtags");
})
and retrieve it like
this.storage.get("hashtags").then(data => {
console.log("retrieved hashtags", data);
this.hashtags = data;
})
On newer devices (Android > 4.4?), this works fine, but on older ones I get [object object] when retrieving the data. It seems that there, objects are saved as strings and cannot be converted back to maps anymore (the driver was asyncStorage).
I have seen that some people store at least arrays in the same way and it seems to work, but since I have a lot of relational data, I would prefer to stick to maps to avoid looping through the arrays for a particular object.
Is there a reliable way to store maps using Storage(2.0.0)? What could be alternatives, if not?
In case of falling back to arrays, what happens to nested objects or arrays of nested objects? like
users:User[] = [new User(1),new User(2)]
let hashtags = [];
hashtags.push(new Hashtag(id,text, users,...))
this.storage.set("hashtags",hashtags)
Thanks!