Closed hummy123 closed 2 years ago
Both work. As you said, approach 1 has better reusability because you can have more than one connector that uses the same dumb-widget, but in most cases you really just have one connector per widget.
I think approach 1 is more clean code, because the widget gets really very independent from the connector. But I have nothing against approach 2 and I agree that is less typing. I think I should at least add approach 2 to the documentation.
Hi all.
I was wondering about the comparatively verbose code in some of the pub.dev documentation, and wanted to ask about it.
To illustrate, the documentation contains a code sample like this:
The parameter list (which can possibly be long) is what I want to draw attention to in particular.
With this code design, if the ViewModel needs changes in its list of parameters, we need to change:
However, if you pass the ViewModel to the view-widget directly instead of primitive types like string/int, the amount of code you need to rewrite and rewire in case of any changes in the ViewModel's parameters decreases.
You will then just need to change:
I think the main advantage of approach (1) is better view-widget reusability by using primitive types. The advantages I see in approach (2) are shorter code and less rewriting/rewiring in case of any changes (and it might also be easier for people learning the library?).
I might have missed some other points of value about why approach 1 is better, but I thought it was worth asking or starting of a discussion at least.