My experience with OOP languages like C# and Java has been good, but I am relatively new to JavaScript/TypeScript. I find callback functions confusing, especially when using them with the BaaS ParseDB.
For example, finding all playlists for a certain user requires a query like this:
var query = new Parse.Query(Playlist);
query.equalTo("user", user);
query.find({
success: function (usersPlaylists: Array<Playlist>) {
alert("Playlists loaded: " + usersPlaylists.length);
}
});
My issue is that the loaded usersPlaylists are only valid within the callback function. I'm struggling to store them in my own objects outside of the callback.
I attempted to create an object with an array of playlist objects and assign each element from the query result to that object's array. However, it didn't work as expected because after the callback function finished, the object's array was empty.
The reason I want to store these playlists in my own objects is so I don't have to query the database for every small operation. For example, if a user wants to know if there is a list with more than 5 elements, I could just use my local list instead of making another query.
Thank you in advance, Tukk