4 ms·
I'm comfortable having one line of HTML in JS, but if it's longer, I want to use a template.
by icedog 13y ago
I'm comfortable having one line of HTML in JS, but if it's longer, I want to use a template.
- peterhunt 13y agoWhat's your reasoning behind this?
- schtoo 13y agoBecause its easier to see the html in context of the whole page or partial... because any significant html contains presentation properties (class names typically but also attrs like placeholder, etc) that I would rather not mix with code/logic... because my html typically contains elements whose sole purpose is to assist in layout which (again) i'd rather not mix with code/logic...
- peterhunt 13y agoWe don't think that separating html and code/logic is a productive separation of concerns. They aren't separate concerns. The code that drives the view and the markup it generates are intimately tied and separating them violates the principle of high cohesion (http://en.wikipedia.org/wiki/Cohesion_(computer_science)#High_cohesion http://en.wikipedia.org/wiki/Cohesion_(computer_science)#Hig...) I think the reason that most people think this is a good separation of concerns is because they used WYSIWYG editors in the past (which are no longer used in large projects) or because they have PHP spaghetti code hangover from the 90s. Mixing code and markup isn't evil in and of itself, it's mixin non-display concerns with display concerns which causes issues. With React, you can use components to separate concerns with finer granularity and in ways that are more tailored to your application.
- icedog 13y agoI'm all for tightly coupled display-logic and its markup; I just don't think it should reside in a JS(X) file unless it's generating a single tag. While I agree that other MVC frameworks are not great (I've seen many of Angular's pains & weaknesses), I think this was a step in the wrong direction. http://jsfiddle.net/vla/Cdrse/(from http://jsfiddle.net/vla/Cdrse/(from https://medium.com/make-your-own-apps/e71bcedc36b https://medium.com/make-your-own-apps/e71bcedc36b) versus https://github.com/petehunt/react-tutorial/blob/master/scripts/example.js https://github.com/petehunt/react-tutorial/blob/master/scrip...
- peterhunt 13y agoI'm curious, what do you mean by "generating a single tag"?