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

Unified Diff: lib/src/js/polymer_base_dart.html

Issue 1351693003: Update to use one less proxy per element (Closed) Base URL: git@github.com:dart-lang/polymer-dart.git@behaviors
Patch Set: update comments Created 5 years, 3 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 | « lib/src/js/polymer_array_methods.html ('k') | lib/src/js/polymer_bind_dart.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/js/polymer_base_dart.html
diff --git a/lib/src/js/polymer_base_dart.html b/lib/src/js/polymer_base_dart.html
index 4dd4929d4fe6e9b276059ef69ddd6eec7d883fcb..65303e5e8b3d3ce429c15e5f75d95cf3883a46d2 100644
--- a/lib/src/js/polymer_base_dart.html
+++ b/lib/src/js/polymer_base_dart.html
@@ -12,11 +12,6 @@ BSD-style license that can be found in the LICENSE file.
this.originalPolymerCreatedCallback();
};
- // Store serialize/deserialize to retain the original behavior when the
- // methods are overriden by PolymerSerialize.
- Polymer.Base.originalSerialize = Polymer.Base.serialize;
- Polymer.Base.originalDeserialize = Polymer.Base.deserialize;
-
Polymer.Dart = {};
// Placeholder for `undefined` return values. This should eventually go
@@ -62,5 +57,50 @@ BSD-style license that can be found in the LICENSE file.
return value;
}
};
+
+ // Remove any `__dartClass__` instances during serialization.
+ Polymer.Dart.serialize = function(value, type) {
+ var dartClass = value.__dartClass__;
+ delete value.__dartClass__;
+ var serialized = Polymer.Base.serialize(value, type);
+ value.__dartClass__ = dartClass;
+ return serialized;
+ };
+
+ // TODO(jakemac): This shouldn't be necessary, but it is today
+ // https://github.com/dart-lang/sdk/issues/24371
+ Polymer.Dart.deserialize = Polymer.Base.deserialize;
+
+ Polymer.Dart.InteropBehavior = {
+ // Secret hook into property changes. Pretty hacky but its more efficient
+ // than using a JsProxy object for the element.
+ _propertyChanged: function(path, newValue, oldValue) {
+ var parts = path.split('.');
+ var thisArg = parts.length == 1 ?
+ this : this.get(parts.slice(0, parts.length - 1));
+ thisArg = thisArg.__dartClass__ || thisArg;
+ Polymer.Dart.propertyChanged(
+ thisArg, parts[parts.length - 1], newValue);
+ },
+
+ notifyPath: function(path, value, fromAbove) {
+ var notified =
+ Polymer.Base.notifyPath.call(this, path, value, fromAbove);
+ if (fromAbove) return notified;
+
+ // If you call notifyPath from dart we need to do manual modifications
+ // on any JsArray or JsObject instances.
+ var parts = this._getPathParts(path);
+ if (parts.length > 1) {
+ var model = this.get(parts.splice(0, parts.length - 1));
+ if (model[parts[0]] != value) model[parts[0]] = value;
+ }
+ return notified;
+ },
+
+ serialize: function(value, type) {
+ return Polymer.Dart.serialize(value, type);
+ }
+ }
})();
</script>
« no previous file with comments | « lib/src/js/polymer_array_methods.html ('k') | lib/src/js/polymer_bind_dart.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698