Difficulty with data binding and firebase-document
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?
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?
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);
}