0

Let me first say that I am new to firebase. As I have been playing with angularfire for a bit, I noticed that $firebaseArray was kinda slow in my project...

But when I used the console to find when the result from firebase was received , I realized that there was a second before that result was displayed in ionic view after it arrived.

If what i'm saying is not really clear, here is a codepen with the $firebaseArray

var lists = $firebaseArray(ref.child('lists'));

And here is an other [codepen] (sorry can't add more than two links) where I added this line after it

lists = [{"name":"test"}];

There is an alert and console log in both codepen that shows when the data arrived.

What I'm asking is : why is there a second delay after the data has already arrived ?

EDIT :

Because 'slow' does not really mean anything, I took a screenshot of my browser's network for the first codepen, showing how much time was needed to display the data : screenshot

  • 1
    "slow" is highly subjective. What action do you measure? How long does it take? How long would you expect it to take? Also note that while it's great that you added a link to a codepen, your question should include the minimum code to reproduce the problem. – Frank van Puffelen Feb 22 '16 at 15:30
  • I mean 'slow' because the data has _already arrived_ from firebase (in my codepen it is available when the alert comes up) and then there is a time before it is displayed (it takes about 1 or 2 seconds for it to be displayed. Which I think is a _lot_, since the data has already arrived. All it needs to do is display it, but it still takes seconds to do it). So I tried doing it with a local JSON array, and this time after the data is availeable (same alert) it displays instantly... – Ramille Estarles Feb 22 '16 at 15:51
  • It shows fast for me in like 0..0001 miliseconds... Its probably something to do with your computer. I cant say anything about that.. – amanuel2 Feb 23 '16 at 00:13
  • @Dsafds the _first_ codepen takes milliseconds (with $firebaseArray) ?? if you're talking about the second one (with JSON) then it's normal. But the first one, I actually tried on different computers which have different internet connections, and it still takes 1 second on a fast one and on a slower one it took _6 seconds_. – Ramille Estarles Feb 23 '16 at 17:45
  • Yes it takes me about 0.3 seconds – amanuel2 Feb 24 '16 at 00:24

1 Answers1

0

Even though I wasn't really looking for it when I found this thread, the answer to my question was given here :

Asynchronous access to an array in Firebase

By the time the browser executes your console.log(userTokens); the data most likely hasn't been loaded yet. So it just prints the object to the console as a placeholder.

By the time it gets to the for loop, the data may or may not yet have been loaded from Firebase.

At some point you clicked the arrow next to the logged userTokens. By that time the data had loaded from Firebase and the console shows the latest data.

So anyway, thank you for your help in trying to answer my question :)

Community
  • 1
  • 1