Re:Things every React.js beginner should know
by Aleman360 on Monday January 25, 2016 @09:12AM
(#10967235)
> After all in every native UI framework you have instructions to draw the widget IN your code -- not as some external additional technology. A widget's C/C++/Obj-C/Swift/Java/C# etc code encapsulates everything about creating it and showing it.
With the notable exception of Windows. XAML strictly enforces code and markup separation. It makes the View layer more toolable and easier to edit by designers who usually don't program.
Re:Things every React.js beginner should know
by tomjen3 on Monday January 25, 2016 @11:41AM
(#10968153)
Thats not really true - you can use some pretty convoluted converters directly into the XAML and you can have those trigger arbitrary functions in your program through one-way binding.
Re:Things every React.js beginner should know
by _pmf_ on Monday January 25, 2016 @11:35AM
(#10968084)
I agree that XAML has the most mature concept, but it cheats by introducing the MVVM pattern, which performs some data mangling that would otherwise be part of the view. Not doing this, you'll end up with custom converters etc.
MVVM is nice regarding testability, but I find it to be overkill for most applications.
Re:Things every React.js beginner should know
by douche on Monday January 25, 2016 @09:21AM
(#10967275)
That is just inside of WPF-land, though. WinForms (which is still pretty excellent for quick-and-dirty GUIs) and other GUI frameworks are more on the classical model.
Re:Things every React.js beginner should know
by Aleman360 on Monday January 25, 2016 @10:11AM
(#10967560)
And UWP, which is the primary UI framework now.
First, in practice what everybody turned up doing was the inverse (add programming logic inside their HTML).
So you still had mixed HTML and JS, but in a way worse way: with ad-hoc and incompatible pseudo-languages (e.g. Angular's ng-repeat etc, Knockout's template instructions, etc), spiced with "JS inside HTML attributes", with no syntax checking (a typo could blow your code in runtime) and convoluted to boot.
Now, having HTML and logic together makes sense when creating widgets/components, as you have all functionality for widget in the same place. After all in every native UI framework you have instructions to draw the widget IN your code -- not as some external additional technology. A widget's C/C++/Obj-C/Swift/Java/C# etc code encapsulates everything about creating it and showing it.
So, the better way is to have all your widget drawing depending on external (or internally stored if you must) state, happen inside the widget code itself. Not to try to manipulate a string template by sprinkling ad-hoc instructions like for-each and if-then.
And here's the better part. React doesn't really mix HTML inside JS.
JSX might look like doing such, but it's just sugar for calling Javascript functions. <div> is essentially something like: React.createElement(null, "div"); So, the "HTML" is just calls to DOM manipulation methods.
So, with React there's just JS, and it handles all the creation of the HTML code for a "component" (widget). It's also composable, so your panel is just a components embedding other components.