firebase.database.Reference.on success?

92 views
Skip to first unread message

Joon Yee Chuah

unread,
Aug 2, 2016, 4:07:25 PM8/2/16
to Firebase Google Group
If I call the 'once' method, I get a promise and can use a success callback. However, if I use the 'on' method, I can only add an event callback and a failure callback. Is there a mechanism to implement some type of success callback? I don't want to assume absence of a failure (such as due to permissions) means a success.

Kato Richardson

unread,
Aug 2, 2016, 6:21:26 PM8/2/16
to Firebase Google Group
Hello Joon,

The `on()` method isn't a great fit for Futures (i.e. promises), since it is really a continuous event stream. Keep in mind that the security rules may also be initially valid, but later a condition could change that causes them to become invalid (i.e. a user's role could change while the on() listener exists, or data could change in a way to render the security rule false). You can't have a simple binary yes or no returned here.

We could just have the promise unresolved indefinitely until a failure occurred, never calling the success, but that would be pretty contradictory to the mental model expected by promises, and could create some strange error cases and unpredictable bugs when chaining then-ables together. So hopefully it makes a bit of sense why we didn't want to encourage this.

The best approach here would be to embrace the event paradigm, and think of this as a continuous stream, rather than a simple CRUD operation. If you're unhappy with that, it's not particularly hard to wrap the on() method and return your own promise, adapting the behavior as you see fit.

☼, Kato

On Tue, Aug 2, 2016 at 1:07 PM, Joon Yee Chuah <jyc...@gmail.com> wrote:
If I call the 'once' method, I get a promise and can use a success callback. However, if I use the 'on' method, I can only add an event callback and a failure callback. Is there a mechanism to implement some type of success callback? I don't want to assume absence of a failure (such as due to permissions) means a success.

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/0db2de43-f2ae-4412-be07-f93d256471f9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

Reply all
Reply to author
Forward
0 new messages