dart-archive / polymer-dart

Polymer support for Dart
https://pub.dartlang.org/packages/polymer
BSD 3-Clause "New" or "Revised" License
181 stars 33 forks source link

Evaluate JsObjectProxy instead of recursive conversion to map in `dartValue`. #586

Open jakemac53 opened 8 years ago

jakemac53 commented 8 years ago

Today given a plain JsObject whose constructor is context['Object'], we convert it to a map and recursively call convertToDart. This could potentially be pretty expensive, and also it loses track of the original JsObject, so you can't modify it. Instead we could create a JsObjectProxy, which is basically this:

class JsObjectProxy extends Object implements JsProxyInterface, JsObject {
  final JsObject jsProxy;

  JsObjectProxy(this.jsProxy);

  operator [](String key) => convertToDart(jsProxy[key]);

  operator []=(String key, value) => jsProxy[key] = convertToJs(value);
}

This would make it lazy, which is good, but repeated access of the same keys would come at a higher cost.

We could do the same for JsArray as well.

jakemac53 commented 8 years ago

This would need to happen during a release candidate release, before official 1.0 as it would be a breaking change.

jakemac53 commented 8 years ago

fyi @sigmundch

jakemac53 commented 8 years ago

We could potentially implement the full Map class as well, but its not clear how the keys of the object should be iterated in order to do that (there are a few different ways of iterating keys of JS objects, none of which are guaranteed to do the "right" thing in all situations).