We started to use Dart's Strong mode with our polymer dart code and honestly it looks terrible. It looks so terrible that I need a second opinion on the matter. It cant be this ugly looking, it honestly cant.
So We were creating a bunch of PolymerDart views using some mix ins for generic code. This generic code is reused everywhere so hence why we made it a mixin.
Our old design:
abstract class MyModel{ ... }
class SubModel extends MyModel with JsProxy{ ... }
@behavior
abstract class MyBehavior implements PolymerBase {
@Property(notify:true)
MyModel model = null;
// ....
}
@PolymerRegister("my-component")
class MyViewModel extends PolymerElement with MyBehavior {
@Property(notify:true)
SubModel model = null;
// ...
}
The purpose was to have a generic model to represent information and we leverage it in the behavior. Since SubModel extends it, we can slot anywhere normally and the behavior would work. My colleague says this is a huge NO and I am confused as to why. He said it a Polymer Issue, so when we leave Polymer it will be able to be done sort of.
He then pushed through the code base a refactor so it works.
@PolymerRegister("my-component")
class MyViewModel extends PolymerElement with MyBehavior {
@Property(notify:true)
MyModel model = null; // <-- changed to parent type from Behavior
//example reference
void test(){
int id = (model as SubModel).id; // <-- using AS to explain what it really is.
}
}
Now he put this EVERYWHERE, updated all references of model.id with (model as SubModel).id. I think this is ugly and just plain wrong. (Granted I get that feeling with everything PolymerDart).
Is this really how this kind of thing is done when dealing with Mixins? Since The mixin already has that definition, we shouldn't need it in the MyViewModel code either.
Can someone explain this to me as to why this is the right thing according to strong mode? Why must this change occur? While I trust in my colleague, something does seem off and I would like a deeper understanding. I believe, that he is correct that maybe it is because entirely due to Polymer Dart, but maybe there is a way to circumventing all property renames, and using (.. as Whatever) everywhere.
analysis_options.yaml:
analyzer:
strong-mode: true
Edit: The reasoning was that since the Model is defined as a property in the behavior, it is non-mutable. We cant override the type in the MyViewModel class. Since SubModel extends MyModel, It should be allowed to exist.