Ryan Zhou
Ryan Zhou

Reputation: 126

How does Firebase's Firebase.on() work?

How does Firebase.on() work? It's suppose to "Listen for data changes at a particular location", according to https://www.firebase.com/docs/web/api/query/on.html ,but how does the client know when to update itself? Is the client also a lightweight server that listens to the Firebase server or does the client automatically do an update every x seconds?

Upvotes: 0

Views: 651

Answers (2)

Frank van Puffelen
Frank van Puffelen

Reputation: 599081

The Firebase client keeps a connection open to the server. Depending on where your app runs, this can either be a web socket or a so-called long-polling connection. Either of these ensures that the server can send new data to the client as soon as it is available.

Upvotes: 3

Georgi-it
Georgi-it

Reputation: 3686

The client listens for changes on the server and you need to update the client data (your objects) in the event callback.

As a suggestion, this can be greatly simplified with firesync.

Upvotes: 0

Related Questions