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

Side by Side 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 unified diff | Download patch
OLDNEW
1 <!-- 1 <!--
2 Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 2 Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
3 for details. All rights reserved. Use of this source code is governed by a 3 for details. All rights reserved. Use of this source code is governed by a
4 BSD-style license that can be found in the LICENSE file. 4 BSD-style license that can be found in the LICENSE file.
5 --> 5 -->
6 <script> 6 <script>
7 (function() { 7 (function() {
8 Polymer.Base.originalPolymerCreatedCallback = 8 Polymer.Base.originalPolymerCreatedCallback =
9 Polymer.Base.createdCallback; 9 Polymer.Base.createdCallback;
10 Polymer.Base.createdCallback = function() { 10 Polymer.Base.createdCallback = function() {
11 if (this.__isPolymerDart__) return; 11 if (this.__isPolymerDart__) return;
12 this.originalPolymerCreatedCallback(); 12 this.originalPolymerCreatedCallback();
13 }; 13 };
14 14
15 // Store serialize/deserialize to retain the original behavior when the
16 // methods are overriden by PolymerSerialize.
17 Polymer.Base.originalSerialize = Polymer.Base.serialize;
18 Polymer.Base.originalDeserialize = Polymer.Base.deserialize;
19
20 Polymer.Dart = {}; 15 Polymer.Dart = {};
21 16
22 // Placeholder for `undefined` return values. This should eventually go 17 // Placeholder for `undefined` return values. This should eventually go
23 // away, once we have dart:js support for `undefined`. 18 // away, once we have dart:js support for `undefined`.
24 Polymer.Dart.undefined = {}; 19 Polymer.Dart.undefined = {};
25 20
26 // Used to get an empty constructor function which doesn't call into dart. 21 // Used to get an empty constructor function which doesn't call into dart.
27 Polymer.Dart.functionFactory = function() { return function() {}; }; 22 Polymer.Dart.functionFactory = function() { return function() {}; };
28 23
29 // Generates a function which accesses a particular property on a dart 24 // Generates a function which accesses a particular property on a dart
(...skipping 25 matching lines...) Expand all
55 // recognize. 50 // recognize.
56 var args = []; 51 var args = [];
57 for (var i = 0; i < arguments.length; i++) { 52 for (var i = 0; i < arguments.length; i++) {
58 args[i] = arguments[i]; 53 args[i] = arguments[i];
59 } 54 }
60 var value = dartFunction(thisArg, args); 55 var value = dartFunction(thisArg, args);
61 if (value === Polymer.Dart.undefined) return undefined; 56 if (value === Polymer.Dart.undefined) return undefined;
62 return value; 57 return value;
63 } 58 }
64 }; 59 };
60
61 // Remove any `__dartClass__` instances during serialization.
62 Polymer.Dart.serialize = function(value, type) {
63 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
64 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
65 var serialized = Polymer.Base.serialize(value, type);
66 value['__dartClass__'] = dartClass;
67 return serialized;
68 };
69
70 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
71 // Secret hook into property changes. Pretty hacky but its more efficient
72 // than using a JsProxy object for the element.
73 _propertyChanged: function(path, newValue, oldValue) {
74 var parts = path.split('.');
75 var thisArg = parts.length == 1 ?
76 this : this.get(parts.slice(0, parts.length - 1));
77 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.
78 Polymer.Dart.propertyChanged(
79 thisArg, parts[parts.length - 1], newValue);
80 },
81
82 notifyPath: function(path, value, fromAbove) {
83 var notified =
84 Polymer.Base.notifyPath.call(this, path, value, fromAbove);
85 if (fromAbove) return notified;
86
87 // If you call notifyPath from dart we need to do manual modifications
88 // on any JsArray or JsObject instances.
89 var parts = this._getPathParts(path);
90 if (parts.length > 1) {
91 var model = this.get(parts.splice(0, parts.length - 1));
92 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
93 }
94 return notified;
95 },
96
97 serialize: function(value, type) {
98 return Polymer.Dart.serialize(value, type);
99 }
100 }
65 })(); 101 })();
66 </script> 102 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698