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

`DomRepeatModel` not returning the item #654

Closed dam0vm3nt closed 8 years ago

dam0vm3nt commented 8 years ago

new DomRepeatModel.fromEvent(e).item always returns null.

Shouldn't item getter be defined as get item => jsElement["def"] ?

jakemac53 commented 8 years ago

Not sure where def is coming from but this does bring up a good point. If you override the items name in the model (using an as attribute) then this item getter won't work. There are a few options here:

  1. Support the generic [] and []=operators, and delete the item getter.
  2. Support the generic [] and []=operators, and leave the item getter in place (but it will only work if you don't have an as attribute)
  3. Make the item getter respect the as attribute so it always returns the model, and leave everything else as is.
  4. Support the generic [] and []=operators, and make the item getter respect the as attribute so it always returns the model.
dam0vm3nt commented 8 years ago

My fault, it should be jsElement[jsElement["dataHost"]["as"]]. And of course it is returning null only when it one uses as attribute.

dam0vm3nt commented 8 years ago

That means option 3, right ?

jakemac53 commented 8 years ago

My first instinct is #3 as well but I am a bit afraid it might lead to confusion. For instance in your template you will still be referring to the item by the name you gave for the as attribute, but then in your code it would always be item. For that reason option #1 might be better, although it is a breaking change.

That leads me to maybe #4 but adding @deprecated to the item getter?

dam0vm3nt commented 8 years ago

yeah, that seams the best choice, I agree.

jakemac53 commented 8 years ago

fwiw, you can also use the get method today with whatever name you used for as

dam0vm3nt commented 8 years ago

ok, thanks for the advice.