OLD | NEW |
1 <!-- | 1 <!-- |
2 @license | 2 @license |
3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. | 3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. |
4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt | 4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt |
5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | 5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt | 6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt |
7 Code distributed by Google as part of the polymer project is also | 7 Code distributed by Google as part of the polymer project is also |
8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt | 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
9 --> | 9 --> |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 readOnly: true | 33 readOnly: true |
34 }, | 34 }, |
35 | 35 |
36 /** | 36 /** |
37 * If true, verbose debugging information will be printed to the console. | 37 * If true, verbose debugging information will be printed to the console. |
38 */ | 38 */ |
39 log: { | 39 log: { |
40 type: Boolean, | 40 type: Boolean, |
41 value: false, | 41 value: false, |
42 reflectToAttribute: true | 42 reflectToAttribute: true |
43 }, | |
44 | |
45 _receivingRemoteChanges: { | |
46 type: Boolean, | |
47 value: false | |
48 } | 43 } |
49 }, | 44 }, |
50 | 45 |
51 observers: [ | 46 observers: [ |
52 '_dataChanged(data.*)' | 47 '_dataChanged(data.*)' |
53 ], | 48 ], |
54 | 49 |
| 50 created: function() { |
| 51 this._receivingLocalChanges = false; |
| 52 this._receivingRemoteChanges = false; |
| 53 }, |
| 54 |
55 get dataAsObject() { | 55 get dataAsObject() { |
56 if (Array.isArray(this.data)) { | 56 if (Array.isArray(this.data)) { |
57 return this.data.reduce(function(object, value, index) { | 57 return this.data.reduce(function(object, value, index) { |
58 object[index] = value; | 58 object[index] = value; |
59 }, {}); | 59 }, {}); |
60 } | 60 } |
61 | 61 |
62 return this.data; | 62 return this.data; |
63 }, | 63 }, |
64 | 64 |
65 /** | 65 /** |
66 * Disconnects the current Firebase Query instance. | 66 * Disconnects the current Firebase Query instance. |
67 */ | 67 */ |
68 disconnect: function() { | 68 disconnect: function() { |
69 this.location = ''; | 69 this.location = ''; |
70 }, | 70 }, |
71 | 71 |
72 _applyLocalDataChanges: function(changes) { | 72 _localDataChanged: function(changes) { |
73 // Virtual.. | 73 // Virtual.. |
74 }, | 74 }, |
75 | 75 |
| 76 _applyLocalDataChange: function(applyChange) { |
| 77 this._receivingLocalChanges = true; |
| 78 applyChange.call(this); |
| 79 this._receivingLocalChanges = false; |
| 80 }, |
| 81 |
76 _applyRemoteDataChange: function(applyChange) { | 82 _applyRemoteDataChange: function(applyChange) { |
77 if (this._applyingLocalDataChanges) { | |
78 return; | |
79 } | |
80 this._receivingRemoteChanges = true; | 83 this._receivingRemoteChanges = true; |
81 applyChange.call(this); | 84 applyChange.call(this); |
82 this._receivingRemoteChanges = false; | 85 this._receivingRemoteChanges = false; |
83 }, | 86 }, |
84 | 87 |
85 _dataChanged: function(changes) { | 88 _dataChanged: function(changes) { |
86 if (this._receivingRemoteChanges) { | 89 if (this._receivingRemoteChanges || |
| 90 this._receivingLocalChanges) { |
87 return; | 91 return; |
88 } | 92 } |
89 | 93 |
90 this._applyingLocalDataChanges = true; | 94 this._localDataChanged(changes); |
91 this._applyLocalDataChanges(changes); | |
92 this._applyingLocalDataChanges = false; | |
93 }, | 95 }, |
94 | 96 |
95 _queryChanged: function(query, oldQuery) { | 97 _queryChanged: function(query, oldQuery) { |
96 if (oldQuery) { | 98 if (oldQuery) { |
97 this._stopListeningToQuery(oldQuery); | 99 this._stopListeningToQuery(oldQuery); |
98 } | 100 } |
99 | 101 |
100 if (query) { | 102 if (query) { |
101 this._listenToQuery(query); | 103 this._listenToQuery(query); |
102 } | 104 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 return arg.val(); | 176 return arg.val(); |
175 } | 177 } |
176 | 178 |
177 return arg; | 179 return arg; |
178 }); | 180 }); |
179 | 181 |
180 console.log.apply(console, args); | 182 console.log.apply(console, args); |
181 } | 183 } |
182 }, | 184 }, |
183 | 185 |
| 186 _warn: function() { |
| 187 if (this.log) { |
| 188 Polymer.Base._warn(this._logf.apply(this, arguments)); |
| 189 } |
| 190 }, |
| 191 |
184 _error: function() { | 192 _error: function() { |
185 if (this.log) { | 193 if (this.log) { |
186 console.error.apply(console, arguments); | 194 Polymer.Base._error(this._logf.apply(this, arguments)); |
187 } | 195 } |
188 } | 196 } |
189 }; | 197 }; |
190 </script> | 198 </script> |
OLD | NEW |