Search code examples
firebasefirebase-realtime-databasepolymerpolymer-1.0polymerfire

Any example using firebase-document


I need to fetch data from a Firebase using firebase-document. I need to further process the data after I receive the response payload. How do I do this?

I read the documentation here, but there are no examples. I see there is a property called transactionsComplete but, again, no examples. Since it's a promise, I am uncertain how to implement it.

Can someone please provide a working code example of how to use the properties or methods of firebase-document to process the data returned by the request and after the transaction is complete?

<firebase-document
    id="doc"
    app-name="my-app">
</firebase-document>
<script>
  _userChanged: function(u) {
    if(u) {
      var doc = this.$.doc;
      var path = [ 'users' , u.uid ].join('/');
      doc.path = path; // this should send a request for data
      // but how do I ensure to process what is returned
      // after and only after it comes back?
    }                   
  },
</script>

Solution

  • Binding the an object to the property data="{{object}}" then you can add an observer or computed property that will return the final value

    <firebase-document
      path="/users/{{userId}}/notes/{{noteId}}"
      data="{{noteData}}">
    </firebase-document>
    

    Using firebase-focument method getStoredValue(path); (ES6 Style)

      this.$.doc.getStoredValue(path)
        .then((response) => {
          console.log(response);
        });