0

Here's the code I have to set some data:

firebase.database().ref(key).set(val);

which returns

Promise {[[PromiseStatus]]: "pending", [[PromiseValue]]: undefined}

It suggests that I can pass it a then/catch handler, but writing:

log = function(x) {console.log(x)
firebase.database().ref(key).set(val).then(log).catch(log)

has the exact same effect (nothing is returned/printed either way)

The wierd thing is that this intermittently works, I just can't figure out why.

2
  • I use these APIs frequently, including with promises like yours. What environment are you running the code in? Can you set up a jsbin that reproduces the problem, so that I can give it a try? Commented Aug 25, 2016 at 1:23
  • @FrankvanPuffelen It seems like set doesn't return anything, even in the promise, but it does actually work. it's get that actually passes a value to the promise. Commented Aug 25, 2016 at 5:43

1 Answer 1

1

.set and .update are both thenable.

function update(node,key,value){
    var ref = firebase.database().ref('/');
    var obj = {};
    obj[key] = value;
    ref.child(node).update(obj)
    .then(function() {
        console.log('Update Ran Successfully');
    });       
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.