This repository was archived by the owner on May 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 139
loop over value keys to check wich value need to be updated #166
Merged
mbleigh
merged 8 commits into
FirebaseExtended:master
from
PolymerEl:sync-only-updated-value
Feb 4, 2017
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
00c4b8d
loop over value keys to check wich value need to be updated
christophe-g 70c88c7
modified check for first sync
christophe-g d31cfe9
this.__firstSync = false instead of delete this.__firstSync
christophe-g a78c8f8
changed __needSync to __needSetData; fixed issue when path is changed…
christophe-g c65ae6b
when the path changes, we should not set data to zeroValue only if no…
christophe-g c449d8b
when the path changes, we should not set data to zeroValue only if no…
christophe-g 3c408bc
reset the data to zeroValue only when data exists, whatever the valid…
christophe-g e610da1
fix value is always empty
christophe-g File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ | |
| ], | ||
|
|
||
| attached: function() { | ||
| this.__needSetData = true; | ||
| this.__refChanged(this.ref, this.ref); | ||
| }, | ||
|
|
||
|
|
@@ -184,13 +185,30 @@ | |
|
|
||
| if (value == null) { | ||
| value = this.zeroValue; | ||
| this.__needSetData = true; | ||
| } | ||
|
|
||
| if (!this.new) { | ||
| if (!this.isNew) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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);
}, |
||
| this.async(function() { | ||
| this.syncToMemory(function() { | ||
| this._log('Updating data from Firebase value:', value); | ||
| this.set('data', value); | ||
|
|
||
| // set the value if: | ||
| // it is the first time we run this (or the path has changed and we are back with zeroValue) | ||
| // or 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.__needSetData || !this.data || typeof value !== 'object' || ( Object.keys(value).length < Object.keys(this.data).length)) { | ||
| this.__needSetData = false; | ||
| return this.set('data', value); | ||
| } | ||
|
|
||
| // now, we loop over keys | ||
| for (var prop in value) { | ||
| if(value[prop] !== this.data[prop]) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will always be true for sub-objects, no?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes it will - see my comment below for a short rationale |
||
| this.set(['data', prop], value[prop]); | ||
| } | ||
| } | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
pathis not a valid one, butoldPathwas.