Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: sky/framework/sky-element/sky-element.sky

Issue 850383002: Add two way data binding. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Make it async. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/framework/sky-element/sky-binder.sky ('k') | sky/tests/framework/observe.sky » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!-- 1 <!--
2 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Copyright 2014 The Chromium Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be 3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file. 4 // found in the LICENSE file.
5 --> 5 -->
6 <import src="sky-binder.sky" as="binder" /> 6 <import src="sky-binder.sky" as="binder" />
7 <script> 7 <script>
8 var attributeConverters = { 8 var attributeConverters = {
9 boolean: function(value) { 9 boolean: function(value) {
10 if (typeof value == 'string') 10 if (typeof value == 'string')
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 attributeChanged(attrName, oldValue, newValue) { 153 attributeChanged(attrName, oldValue, newValue) {
154 // override 154 // override
155 } 155 }
156 156
157 shadowRootReady() { 157 shadowRootReady() {
158 // override 158 // override
159 } 159 }
160 160
161 createdCallback() { 161 createdCallback() {
162 this.isAttached = false; 162 this.isAttached = false;
163 this.propertyBindings = null;
164 this.dirtyPropertyBindings = null;
163 this.created(); 165 this.created();
164 166
165 Object.preventExtensions(this); 167 Object.preventExtensions(this);
166 168
167 // Invoke attributeChanged callback when element is first created too. 169 // Invoke attributeChanged callback when element is first created too.
168 var attributes = this.getAttributes(); 170 var attributes = this.getAttributes();
169 for (var i = 0; i < attributes.length; ++i) { 171 for (var i = 0; i < attributes.length; ++i) {
170 var attribute = attributes[i]; 172 var attribute = attributes[i];
171 this.attributeChangedCallback(attribute.name, null, attribute.value); 173 this.attributeChangedCallback(attribute.name, null, attribute.value);
172 } 174 }
(...skipping 28 matching lines...) Expand all
201 this.attributeChanged(name, oldValue, newValue); 203 this.attributeChanged(name, oldValue, newValue);
202 var registration = registrations.get(this.localName); 204 var registration = registrations.get(this.localName);
203 var converter = registration.attributes.get(name); 205 var converter = registration.attributes.get(name);
204 if (converter) { 206 if (converter) {
205 this.notifyPropertyChanged(name, converter(oldValue), 207 this.notifyPropertyChanged(name, converter(oldValue),
206 converter(newValue)); 208 converter(newValue));
207 } 209 }
208 } 210 }
209 211
210 notifyPropertyChanged(name, oldValue, newValue) { 212 notifyPropertyChanged(name, oldValue, newValue) {
213 if (oldValue == newValue)
214 return;
211 var notifier = Object.getNotifier(this); 215 var notifier = Object.getNotifier(this);
212 notifier.notify({ 216 notifier.notify({
213 type: 'update', 217 type: 'update',
214 name: name, 218 name: name,
215 oldValue: oldValue, 219 oldValue: oldValue,
216 }); 220 });
217 var handler = this[name + 'Changed']; 221 var handler = this[name + 'Changed'];
218 if (typeof handler == 'function') 222 if (typeof handler == 'function')
219 handler.call(this, oldValue, newValue); 223 handler.call(this, oldValue, newValue);
224 this.schedulePropertyBindingUpdate(name);
225 }
226
227 addPropertyBinding(name, binding) {
228 if (!this.propertyBindings)
229 this.propertyBindings = new Map();
230 this.propertyBindings.set(name, binding);
231 }
232
233 getPropertyBinding(name) {
234 if (!this.propertyBindings)
235 return null;
236 return this.propertyBindings.get(name);
237 }
238
239 schedulePropertyBindingUpdate(name) {
240 if (!this.dirtyPropertyBindings) {
241 this.dirtyPropertyBindings = new Set();
242 Promise.resolve().then(this.updatePropertyBindings.bind(this));
243 }
244 this.dirtyPropertyBindings.add(name);
245 }
246
247 updatePropertyBindings() {
248 for (var name of this.dirtyPropertyBindings) {
249 var binding = this.getPropertyBinding(name);
250 if (binding) {
251 binding.setValue(this[name]);
252 binding.discardChanges();
253 }
254 }
255 this.dirtyPropertyBindings = null;
220 } 256 }
221 }; 257 };
222 258
223 module.exports = SkyElement; 259 module.exports = SkyElement;
224 </script> 260 </script>
OLDNEW
« no previous file with comments | « sky/framework/sky-element/sky-binder.sky ('k') | sky/tests/framework/observe.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698