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

$['id'] should return Element instead of js.JsObject #640

Closed zoechi closed 8 years ago

zoechi commented 8 years ago
abstract class PolymerBase implements CustomElementProxyMixin {
  /// The underlying Js Element's `$` property.
  js.JsObject get $ => jsElement[r'$'];

Is this intentional? It breaks autocompletion.

jakemac53 commented 8 years ago

The $ object itself is a JsObject. Unfortunately the JsObject class doesn't support generics so there isn't much we can do here :(.

zoechi commented 8 years ago

It seems it always can be cast to an Element. Are there exceptions?

jakemac53 commented 8 years ago

The return value of the [] operator is always an Element yes, but I don't know of an automated way to deal with that (without wrapping the $ object or something).

refi64 commented 8 years ago

Would anyone be interested in a PR that adds something (maybe $+?) that wraps the cast to Element?

zoechi commented 8 years ago

Why can't you just change the return type from js.JsObject to Element when on call-site Element x = $['someid']; seems to work fine.?

jakemac53 commented 8 years ago

This getter is for $, which is a JsObject and not an Element. The [] operator of that object is what is returning the Element.

zoechi commented 8 years ago

Now I get it! Sorry, too much debugging today :-/ $ would need to return an instance of a class that wraps JsObject and implements [] so that calls are forwarded to the wrapped JsObject and declare a return type Element. Do you think it's to expensive to create such an instance? I guess it would need only one per element instance?