From 8d7a58e59ce1f8497d0f45ddecf4132751a41848 Mon Sep 17 00:00:00 2001 From: Cameron Date: Thu, 10 Mar 2016 21:20:12 +0000 Subject: [PATCH] Updated firebase query method .once to optionally return a promise --- firebase/firebase-tests.ts | 9 ++++++++- firebase/firebase.d.ts | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/firebase/firebase-tests.ts b/firebase/firebase-tests.ts index ede8744017..2596e058c8 100644 --- a/firebase/firebase-tests.ts +++ b/firebase/firebase-tests.ts @@ -700,11 +700,18 @@ wilmaRef.transaction(function(currentData) { }, { x: 1 }); } +() => { + // Use a Promise in place of a callback + firebaseRef.once('value').then(function(dataSnapshot){ + // handle read data + }) +} + /* * FirebaseQuery.orderByChild() */ () => { - // For example, using our sample Firebase of dinosaur facts, + // For example, using our sample Firebase of dinosaur facts, // we can read all dinosaurs ordered by height using the following query: var ref = new Firebase("https://dinosaur-facts.firebaseio.com/"); ref.orderByChild("height").on("child_added", function (snapshot) { diff --git a/firebase/firebase.d.ts b/firebase/firebase.d.ts index c4cda65bfb..da65fb9116 100644 --- a/firebase/firebase.d.ts +++ b/firebase/firebase.d.ts @@ -109,6 +109,7 @@ interface FirebaseQuery { */ once(eventType: string, successCallback: (dataSnapshot: FirebaseDataSnapshot) => void, context?: Object): void; once(eventType: string, successCallback: (dataSnapshot: FirebaseDataSnapshot) => void, failureCallback?: (error: any) => void, context?: Object): void; + once(eventType: string): Promise /** * Generates a new Query object ordered by the specified child key. */