Skip to content
This repository was archived by the owner on May 19, 2025. It is now read-only.

added exists attribute, reflecting whether we have data at a given path#234

Merged
tjmonsi merged 8 commits intoFirebaseExtended:masterfrom
christophe-g:knowIfExists
Feb 21, 2018
Merged

added exists attribute, reflecting whether we have data at a given path#234
tjmonsi merged 8 commits intoFirebaseExtended:masterfrom
christophe-g:knowIfExists

Conversation

@christophe-g
Copy link
Copy Markdown
Contributor

@christophe-g christophe-g commented Jun 17, 2017

Replace and close #177.
Follows #33 discussion.

An "empty-result" event is fired by firebase-document or firebase-query to notify that the path does not hold any data.

…th. An "empty-result" event is fired by firebase-document or firebase-query to notify that the path does not hold any data.
@christophe-g
Copy link
Copy Markdown
Contributor Author

Any new on this one ?
Thanks.

@JosefJezek
Copy link
Copy Markdown

@mbleigh FYI

@tjmonsi
Copy link
Copy Markdown
Contributor

tjmonsi commented Sep 6, 2017

@christophe-g can you check it again as it has some conflicts with firebase-query

@christophe-g
Copy link
Copy Markdown
Contributor Author

@tjmonsi - thanks.
@mbleigh - for your review ; )

Copy link
Copy Markdown
Contributor

@tjmonsi tjmonsi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use the exist() method to show that a value on the snapshot really exists given a path?

I could edit this PR and add the ready attribute as well in this PR if you want or you can do it. :)

@christophe-g
Copy link
Copy Markdown
Contributor Author

christophe-g commented Oct 31, 2017

@tjmonsi - thanks !
@andrewspy - for info

Why not use the exist() method to show that a value on the snapshot really exists given a path?

I am not sure which exist method you are referring to - if there is one, the reason for not using is certainly that this PR predates an exist implementation.

If you are referring to snapshot.exists, the reason is to better integrate the PR within existing code flow.

For instance, as we already have this (with value == null which is equivalent to snapshot.exists() ):

    __onFirebaseValue: function(snapshot) {
      var value = snapshot.val();
      if (value == null) {
        value = this.zeroValue;
        this.__needSetData = true;
      }

It is pretty natural to set exists to false there, without adding one additional check.

I could edit this PR and add the ready attribute as well in this PR if you want or you can do it. :)

I would rather keep exists instead of ready as it conveys the idea of whether data exists or not. ready just indicates that database round-trip is completed - but I am open to discuss it ; )

@tjmonsi
Copy link
Copy Markdown
Contributor

tjmonsi commented Oct 31, 2017

var value = snapshot.val();
      if (value == null) {
        value = this.zeroValue;
        this.__needSetData = true;
      }

I think we can change this as

this.exists = snapshot.exist();
if (!this.exists) {
  ...
}

I'm still trying to find time for this but I think I can squeeze this in today with ready
If that's alright with you, I'll do the changes.

@andrewspy
Copy link
Copy Markdown

@christophe-g @tjmonsi In my opinion, both exists and ready serve a different purpose.

exists should refer to the snapshot.exists() in official firebase Nodejs API to make the API complete, but in Polymerfire land, it is useful for a developer to know when data is ready, with the data guarantee available for data-binding and consumption purpose (assuming the data does exist).

In short, exists is meant to use pragmatically, while ready is meant to use with Polymer + Polymerfire specifically for data-binding and consumption purpose.

@christophe-g
Copy link
Copy Markdown
Contributor Author

@tjmonsi

If that's alright with you, I'll do the changes.

That is alright - I am pretty stretched!

@tjmonsi
Copy link
Copy Markdown
Contributor

tjmonsi commented Oct 31, 2017

@christophe-g gotyah. Will work on it in a bit

@merlinnot
Copy link
Copy Markdown
Contributor

merlinnot commented Jan 5, 2018

I see the reasoning behind this, but there are few things I’d like to discuss:

  1. Since the value of exists is based on a value of data, wouldn’t it be better to make it a computed property? Since we cannot use setProperties here to ensure the property changes run as a coherent set I think it would be better to set the value of exists after changes to the data itself are made.
  2. Do we really need this event? Polymer provides us with on-exists-changed, isn’t that enough?
  3. I’d personally prefer to set this value to undefined if it’s unknown. Why did you decide to go with null?

@christophe-g
Copy link
Copy Markdown
Contributor Author

@merlinnot - thanks for looking at this.

  1. If I remember correctly, I was worried about performance penalties in adding computed properties listening to data changes. As we already indirectly observe data modification in firebase callbacks (__onFirebaseValue for firebase-document and __onChildAdded, __onChildRemoved for firebase-query), I am assuming (without testing) that performance penalties are minimum with current implementation.

  2. I am not using th empty-result event. It was suggested in the related firebase-document defaults to {} before resolving #33 discussion. We can remove it as far as I am concerned.

  3. Polymer 1.0 does not fire computed/observed properties when one of the parameters are undefined. For the 1.0 branch - as exists property notifies and is potentially bound to external components - setting undefined will partially break the purpose of this PR. I am fine with undefined for the 2.0 branch.

Comment thread firebase-database-behavior.html Outdated
/**
* the element is notified that the path does not hold any data (fired by firebase-document or firebase query)
*
* @event empty-result
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This event is unnecessary. One can use on-exists-changed which Polymer fires by default.

Comment thread firebase-database-behavior.html Outdated

/**
* `exists` is set to `true` when the data actually exists for the specified path; `false` otherwise.
* When we are unable to determine whether data exists or not (e.g. first round trip to the server not yet performed) the value is `null`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please split this comment into multiple lines so it's more readable without line wrapping? ❤️

Comment thread firebase-query.html Outdated
value = this.__snapshotToValue(snapshot);

this.__map[key] = value;
this._setExists(true);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be moved after an assignment of a value to the data property.

Comment thread firebase-query.html Outdated
var key = snapshot.key;

if (this.__initialLoadDone) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have to add a new line here.

Comment thread firebase-query.html Outdated
* the callback if the query changes
*/
query.on('value', this.__onFirebaseValue, this.__onError, this);
this._setExists(null);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one can be moved immediately after query.offs

Comment thread firebase-query.html
this.syncToMemory(function() {
this.splice('data', this.__indexFromKey(key), 1);
});
if (this.data.length === 0) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... what if data is changed in some property effect? Don't you think we should get the length of data before calling this.splice?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are just assessing whether we have data or not. Sounds correct to me,

@merlinnot
Copy link
Copy Markdown
Contributor

merlinnot commented Jan 8, 2018

  1. I see, that's ok.
  2. Let's remove it.
  3. Ok, I'm fine with that. I guess we still have to support v1 guys ;)

Could you please add some basic tests and resolve conflicts? Just a few test 😀 😃

@tjmonsi what about ready? ;)

@christophe-g
Copy link
Copy Markdown
Contributor Author

@tjmonsi @merlinnot - ready for review

@christophe-g
Copy link
Copy Markdown
Contributor Author

@merlinnot - any news on this ?

Just a few test 😀 😃

There are even tests !
Thnks

@merlinnot
Copy link
Copy Markdown
Contributor

@christophe-g I've seen all the work you've done and I'm really happy to see progress on this, but I'm not an owner of this repository and even if I would I'd like to wait for more people to take a look on this.

Unfortunately, it's kinda hard to reach any of the owners lately, I don't really know why. We have to wait for @tjmonsi or @mbleigh to have some time to take a look at this. I've even tried to tweet the Firebase team but got no response.

@tjmonsi tjmonsi merged commit 6ca00b6 into FirebaseExtended:master Feb 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants