I do not understand why tmpModel or this.models dose not working (not sorting) but if I create custom array of object before Array.prototype.sort.call it will work …
You’re using futures (i.e. Promises) in the for loop, which means that your array isn’t constructed by the time that you hit the call to sort.
You need to wait for all the for loop promises to finish first, probably by constructing an array and then using Promise.All. Then you can sort your array.
Theoretically, but not the way you’re doing it now. Follow @SigmundFroyd’s advice, build an array of Promises consisting of all the actions needed for each element going into the list of models, and use Promise.all to wait until they have all completed before you can consider tmpModel built.
That loop with all the pushing is kinda clunky. I get that it has to be written that way because you have to keep calling item(), but it sure would be nifty if there was some way to do it with Array.map().
Agreed. I’ve never understood the decision to have the API have an item function rather than just being an array. In one of my projects I wound up just creating a wrapper in order to be able to use Array.map(). It was a great decision.
Literally everything I know about Firebase I have learned from seeing people post problematic code here, but I would assume it’s for efficiency, so that one can choose only to fetch certain items without incurring the overhead for fetching all of them up front.