polymerfire icon indicating copy to clipboard operation
polymerfire copied to clipboard

Difficulty with data binding and firebase-document

Open esd100 opened this issue 8 years ago • 2 comments

Description

I have put in several firebase-document elements and am not getting the result that I expect. For example,

    <firebase-messaging
      id="messaging"
      app-name="My application"
      token="{{token}}"
      on-message="handleMessage">
    </firebase-messaging>

    <firebase-document
      id="tokenDocument"
      app-name="My application"
      path="/users/[[user.uid]]/token"
      data="[[token]]">
    </firebase-document>

Expected outcome

I expect that when {{token}} becomes defined after calling this.$.messaging.requestPermission(), that firebase-document would add that newly defined data="[[token}}"

Actual outcome

The data binding and firebase-document don't seem to be behaving as I would expect. Nothing gets added to my firebase database when the property is updated.

Am I doing something wrong?

esd100 avatar May 24 '17 00:05 esd100

Can you give us a link to the repo on where this is? Can you check if you can do this manually like putting in the console log: firebase.database() and show us the result?

tjmonsi avatar May 24 '17 13:05 tjmonsi

Hi @tjmonsi,

Thanks for helping out.

I'm not sure what you mean by the link to the repo? Can you please clarify what you mean by this. Sorry if that is a stupid question.

The answer to the second question is that yes, I can do this manually, which is what I have done as a workaround because I wasn't getting the behavior that I was expecting.

For example,

<my-firebase-syncing-element user="[[user]]" logid="[[logid]]" new-log="[[newLog]]" ></my-firebase-syncing-element>

with the properties of my-firebase-syncing-element, being

properties: {
        user: {
          type: Object,
          notify: true
        },
        logid: {
          type: String,
          notify: true
        },
        newLog: {
          type: Object,
          notify: true
        }
},

Instead of doing something like this,

    <firebase-document
      id="addLogtoLogs"
      app-name="My Application"
      path="/Logs/[[user.uid]]/[[logid]]"
      data="[[newLog]]"
      log>
    </firebase-document>

which doesn't seem to work.

I ended up doing something like this,

observers: ['_sync(user,logid,newLog)'],

_sync: function(user,logid,newLog) {
        var path1 = firebase.app('My Application').database().ref(`/logs/${user.uid}/${logid}`);
        path1.update(newLog);
      }

esd100 avatar May 26 '17 21:05 esd100