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

Conversation

@christophe-g
Copy link
Contributor

Should resolve #88 and #56.

Copy link
Contributor

@mbleigh mbleigh left a comment

Choose a reason for hiding this comment

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

Thanks for taking a look at this! I have a few concerns:

  1. The performance of doing two Object.keys().length on what could be arbitrarily large JSON blobs
  2. This is going to solve things for a subset of cases -- all nested object properties will still trigger on every update.

@cdata I'd be curious to hear your thoughts on this.


// set the value if this.data does not exist or value is primitive or if firebase value obj contain less keys than this.data (https://github.com/Polymer/polymer/issues/2565)
if (this.__firstSync || !this.data || typeof value !== 'object' || ( Object.keys(value).length < Object.keys(this.data).length)) {
delete this.__firstSync;
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer this.__firstSync = false

Copy link
Contributor Author

Choose a reason for hiding this comment

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

o.k. - will update that


// now, we loop over keys
for (var prop in value) {
if(value[prop] !== this.data[prop]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This will always be true for sub-objects, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes it will - see my comment below for a short rationale

@christophe-g
Copy link
Contributor Author

@mbleigh thanks for your comments, truly appreciated.

For very large JSON blob, I would tend to think that other part of data processing will weight on performance way more than Object.key() (I am thinking of snapshot.val() in particular - which is process intensive and invoked by firebase-document on every firebase value update).

Re. nested Object properties - yes they will still trigger on every update. I was reluctant to recurse down the entire tree because the problem this PR is trying to fix is to avoid observers to be fired every time a an update is made on a bound Object. A construct like _observe(data.myProp) is pretty common, whereas observe(data.myProp.mySubProp) is a bit less likely.

}

if (!this.new) {
if (!this.isNew) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be if (!this.isNew()) {?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

isNew is defined via its getter

    get isNew() {
      return this.disabled || !this.__pathReady(this.path);
    },

… for firebase-document: we need to set the data in this case as well
…t null. The old behavior caused data to be instantiated twice to zeroValue when path changed from null -> /userData//profile -> /userData/uid/profile
…t null. The old behavior caused data to be instantiated twice to zeroValue when path changed from null -> /userData//profile -> /userData/uid/profile
@christophe-g christophe-g force-pushed the sync-only-updated-value branch from cc94e13 to c449d8b Compare January 3, 2017 12:23

__pathChanged: function(path, oldPath) {
if (oldPath != null && !this.disabled && this.__pathReady(path)) {
if (!this.disabled && !this.valueIsEmpty(this.data)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we also want to handle the case where path is not a valid one, but oldPath was.

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.

Sub-property change notifies the other sub-properties

3 participants