Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit acde236

Browse files
Merge pull request #20 from Lampei/master
Return generated key during push for iOS and android
2 parents 8fcf2d3 + a92cb06 commit acde236

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

firebase.android.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,11 @@ firebase.removeEventListener = function (listener, path) {
227227
firebase.push = function (path, val) {
228228
return new Promise(function (resolve, reject) {
229229
try {
230-
instance.child(path).push().setValue(firebase.toHashMap(val));
231-
resolve();
230+
var pushInstance = instance.child(path).push();
231+
pushInstance.setValue(firebase.toHashMap(val));
232+
resolve({
233+
key: pushInstance.getKey()
234+
});
232235
} catch (ex) {
233236
console.log("Error in firebase.push: " + ex);
234237
reject(ex);

firebase.ios.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,11 @@ firebase.addValueEventListener = function (updateCallback, path) {
182182
firebase.push = function (path, val) {
183183
return new Promise(function (resolve, reject) {
184184
try {
185-
instance.childByAppendingPath(path).childByAutoId().setValue(val);
186-
resolve();
185+
var ref = instance.childByAppendingPath(path).childByAutoId();
186+
ref.setValue(val);
187+
resolve({
188+
key: ref.key
189+
});
187190
} catch (ex) {
188191
console.log("Error in firebase.push: " + ex);
189192
reject(ex);

0 commit comments

Comments
 (0)