5 ms·
Just because your HTML, JS and CSS are in different files doesn't change the fact that they are tightly coupled. React dispenses with this superficial separatio
by kyllo 12y ago
Just because your HTML, JS and CSS are in different files doesn't change the fact that they are tightly coupled. React dispenses with this superficial separation and groups presentation, behavior and styling of the same UI element together. I've found it much easier to reason about.
- timepiece 12y agoBut if these individual components share any code between them, you'd still have to write the same lines over and over again for each component. So, how do you reason about that?
- lobster_johnson 12y agoThere is no reason that components can't share code. It's just JavaScript. Extract common code into libraries, mixins or even components. For example, we frequently create generic containers that modify the behavior of the child or parent. One example is a container that automatically sets its children to be "sticky" once you scroll past it. Another common parent is one that renders it's children is a modal (lightbox, dialog or similar). Another is a child component that, if you nest it into another, can notify the parent whenever its dimensions change.
- timepiece 12y agoSo you guys are basically defining a new inheritance model in your app, right?
- lobster_johnson 12y agoIt's not inheritance at all. The code sharing is across interface boundaries, not like inheritance where, say, changing a member variable can break descendant classes. Instantiating a component is just like declaring a variable.
- timepiece 12y agoSo, you're getting rid of inheritance altogether and settling for this interface boundary sharing notion?
- lobster_johnson 12y agoYes, we generally only use mixins. Classical OO inheritance causes coupling problems that composition doesn't.
- yazaddaruvala 12y ago> getting rid of inheritance altogether and settling for this interface boundary sharing You claim it is "settling" but I'll try to explain why its not only not "settling" but actually encouraging best practices. I'm not sure what language you're most familiar with but since you're talking about inheritance I'll try to provide Java analogies. Hierarchal components => Hierarchical composition of classes Mixins => Interfaces with default implementations (possible as of Java 8) Inheritance, as defined by the OO paradigm, is very rarely the correct solution. Even in a language like Java, when it comes to classes, the best practice is to use composition over inheritance. If you haven't heard this before, or you don't agree, sorry but I'd rather not get into this myself. There are a ton of really good resources online about this, they will do a far better job explaining than I would.
- timepiece 12y agoI aint no traditionalist or a Java supremacist :). I'm just an ordinary guy with passion for anything web development and I happen to like javascript a lot. So, I'm okay with non classical inheritance or any other non conventional constructs that would make our lives easier but I'm really skeptical about the direction that these frameworks is taking the industry as a whole in, and I believe that their lack of enthusiasm for established best practices and breaking the rules without offering well thought and coherent alternatives is worrisome.
- lobster_johnson 12y ago