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

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: redo! 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
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..04219aff9fca6cc19dca6e68fe5a18d5f3cb0b49 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,46 @@ 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__'];
Siggi Cherem (dart-lang) 2015/09/17 21:11:59 Since this is JS, use the field directly? var d
jakemac 2015/09/23 17:37:08 done
+ value['__dartClass__'] = undefined;
Siggi Cherem (dart-lang) 2015/09/17 21:11:59 Does Polymer.Base.serialize depend on Object.keys?
jakemac 2015/09/23 17:37:08 It seemed to work fine, but deleting it entirely i
+ var serialized = Polymer.Base.serialize(value, type);
+ value['__dartClass__'] = dartClass;
+ return serialized;
+ };
+
+ Polymer.Dart.Behavior = {
Siggi Cherem (dart-lang) 2015/09/17 21:11:59 instead of a behavior, would it make sense to make
jakemac 2015/09/23 17:37:08 I think the behavior actually makes a lot of sense
+ // 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.__dartClass__ : thisArg;
Siggi Cherem (dart-lang) 2015/09/17 21:11:59 Or: thisArg = thisArg.__dartClass__ || thisArg;
jakemac 2015/09/23 17:37:08 Done.
+ 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;
Siggi Cherem (dart-lang) 2015/09/17 21:11:59 do we expect the value to always be a string liter
jakemac 2015/09/23 17:37:08 good catch, I don't think it would ever be created
+ }
+ return notified;
+ },
+
+ serialize: function(value, type) {
+ return Polymer.Dart.serialize(value, type);
+ }
+ }
})();
</script>

Powered by Google App Engine
This is Rietveld 408576698