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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/framework/sky-element/sky-element.sky
diff --git a/sky/framework/sky-element/sky-element.sky b/sky/framework/sky-element/sky-element.sky
index a76874a5f1215af1bbefca5594b9edc2b2c1c2e8..7b7933ab35709505eee6b2118c3228a6a28ed7ea 100644
--- a/sky/framework/sky-element/sky-element.sky
+++ b/sky/framework/sky-element/sky-element.sky
@@ -160,6 +160,8 @@ class SkyElement extends HTMLElement {
createdCallback() {
this.isAttached = false;
+ this.propertyBindings = null;
+ this.dirtyPropertyBindings = null;
this.created();
Object.preventExtensions(this);
@@ -208,6 +210,8 @@ class SkyElement extends HTMLElement {
}
notifyPropertyChanged(name, oldValue, newValue) {
+ if (oldValue == newValue)
+ return;
var notifier = Object.getNotifier(this);
notifier.notify({
type: 'update',
@@ -217,6 +221,38 @@ class SkyElement extends HTMLElement {
var handler = this[name + 'Changed'];
if (typeof handler == 'function')
handler.call(this, oldValue, newValue);
+ this.schedulePropertyBindingUpdate(name);
+ }
+
+ addPropertyBinding(name, binding) {
+ if (!this.propertyBindings)
+ this.propertyBindings = new Map();
+ this.propertyBindings.set(name, binding);
+ }
+
+ getPropertyBinding(name) {
+ if (!this.propertyBindings)
+ return null;
+ return this.propertyBindings.get(name);
+ }
+
+ schedulePropertyBindingUpdate(name) {
+ if (!this.dirtyPropertyBindings) {
+ this.dirtyPropertyBindings = new Set();
+ Promise.resolve().then(this.updatePropertyBindings.bind(this));
+ }
+ this.dirtyPropertyBindings.add(name);
+ }
+
+ updatePropertyBindings() {
+ for (var name of this.dirtyPropertyBindings) {
+ var binding = this.getPropertyBinding(name);
+ if (binding) {
+ binding.setValue(this[name]);
+ binding.discardChanges();
+ }
+ }
+ this.dirtyPropertyBindings = null;
}
};
« 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