I can't see any fundamental reason why generating the DOM with React would be faster than generating the DOM with Web Components - They're doing the same thing; it's a matter of time before they even out (if they haven't already).
I think that Web Components would end up faster ultimately due to native browser support (more room to optimise).
What about automatic semicolon insertion (ASI)? This makes it impossible to internalize how the JS implementation will interpret your code without memorizing a bunch of special cases, and makes "newline" semantically significant even if you only intend it for formatting your code.
It's never going to be fixed because of backwards compatibility. I can put up with a lot of language peculiarities, but I don't like wondering if some random "return" statement in my code is going to misbehave because of extra whitespace.
This is enough reason for me to keep looking for an ideal language.
Remember the bad old days of BASIC? You only needed that extra delimiter (colon, rather than semi) when you were going to put multiple statements on one line :-)
Yeah, minifiers are often too dumb to accept valid input text :-(
I'd be happy to treat JS as "statements end with a newline, not semicolon", if that were consistently true.
The paradox of Javascript: Do statements end in a semicolon, or newline? If you answer either way, you're sometimes wrong. As far as I can tell this is the only misfeature of JS that is really unfixable.
We do think it helps to create maintainable apps though, and it is fast enough for practical use cases despite its immutable design. That's why we use it at Facebook.
* Inconsistencies or duplicated code between initial render and updates.
* Having to write code for N^2 transitions between N valid states instead of N valid states themselves.
* Harder to ensure DOM operation order across different parts of the codebase doesn’t produce jank.
Sure, this is all possible to solve, but in my experience I just ended up with a crappy version of React.
jQuery code is well known to be hard to maintain when it changes things based on element-types, classes and id's nested in each other.
var widget = require('./widget');
widget.foo('bar');
And the widget handles the jQuery'ing for you. module.exports = {
foo: function(s) { $('.widget').text(s) }
}- it breaks immediately if there is more than one '.widget' on the page
- your app will get out-of-sync DOM updates because different parts will flush changes to the DOM at different times (React is DOM = f(state, time), so if multiple changes happen in f, they all be flushed to DOM in one go)
Honest question, because I use Javascript just infrequently enough to have to look this up every time (and it's possible the reported solutions are old), is there a good concise universal way (or two, at most) to determine the type of the variable I may have? It seems it's always a tossup between typeof, instanceof, == null and == undefined, and to my eyes that's way too many.
EDIT: Of course, I forget that arrays also have `typeof` "object"... Again, probably best to just start using length and indexing and hope for the best.
If the type you're testing for is not one of the builtin literal types, you can just use instanceof.
I guess an alternative is foo.constructor and foo.constructor.name, which will give you a string if you want that.
That's why many dynamic languages allow access to the type through a string representation.
Best just to see if it quacks, or barks :-)
(i.e. - does the object define a given function/"method")
['Hello', 'world'].forEach( text => MyComponent
.appendChild(document.createElement('p'))
.appendChild(document.createElement('span'))
.textContent = text
)> it's either careless or dishonest to compare the two without acknowledging the possibility of using a helper function or two to simplify the second one, as JavaScript developers have been doing routinely for multiple decades.
To quote from the article:
--- start quote ---
DOM APIs are horrible, cumbersome, awkward and clunky. Polymer and others are bravely trying to use DOM APIs only, but even they resort to innerHTML anywhere they don’t have to put on a show (tests, for example). When Web Components take root, the web will be flooded with less performant innerHTMLs and possibly re-implementations of snabbdoms and virtual-doms (obviously incompatible)
--- end quote ---
Similarly, if people are building reusable components it's not clear why using different virtualdom libraries or not using one at all is a problem. Doesn't sound software engineering practice recommend a well-defined public interface rather than deeply interconnecting them like that? Besides, this is the web: what are the odds that you wouldn't quickly hit a problem where component X depends on v1.2.3 but component Y requires v2.3.4?
I'd be interested in seeing those tests.
React apps are usually built with many layers of components that returns another components. And with standard Web API, there will be significantly more DOM nodes because each component is a DOM node.
You can check it out yourself: https://localvoid.github.io/uibench/
I highly recommend the author's article about it: https://medium.com/@localvoid/how-to-win-in-web-framework-be...
You cannot buy into Web Components without buying into at least Polymer to supply you with data binding.
If you don't like React's size, there are slimmer options: Inferno, Preact etc.
Why? You can use Polymer and not its data binding. In fact you can use its polyfills and deal with mostly the standard based APIs. X-Tags and many others also use Polymer's polyfills.
DOM APIs are awkward as hell. But you can create Web Components and handle the data binding yourself. It's actually pretty easy to roll your own data binding. Now whether you should is another matter.
> This gets progressively worse as your components grow in complexity. Imagine adding a span around the text in p?
In this case you simply type in the span inside the template tag similar to what you have in the React JSX and then just importNode the contents into your webcomponent.
Nope, it's not. It's a thin XML-like DSL which translated into Javascript calls: http://bit.ly/2nC6fdu
This is completely and utterly false. What are you basing your assertion on?
SkateJS's TodoMVC uses JSX[1]. Does that also imply that all Web Components need to use JSX? I don't see any logic in your claims.
[1]: https://github.com/skatejs/todomvc/blob/skatejs/examples/ska...
“This was cumbersome. This was limiting. You could not prototype easily and quickly. You could not easily escape the limitations of UI libraries. etc. etc. etc.”
It would have been far more interesting to look at whether the broadest claims were even true, or why people ran into problems using various libraries. Every time I've done a test, React is significantly slower than using standard JavaScript + DOM but that's the wrong question to ask when you really care about whether it's a) fast enough and b) helping you write code faster, reducing maintenance or sharing costs, etc.
All I got from this is that using React makes life easier than calling the DOM APIs directly every time, which is technically true but doesn't say anything about e.g. how WebComponents compare when using abstraction following the best practices of software developers since something like the 1950s.
The “easy-peasy” example is:
The alternative given is: Since the first example requires 140KB of React code plus a ton of setup code to get to that it's either careless or dishonest to compare the two without acknowledging the possibility of using a helper function or two to simplify the second one, as JavaScript developers have been doing routinely for multiple decades.Again, not a slam on React, just this kind of unhelpful advocacy. It'd be a lot more interesting to compare real examples with multiple libraries and talk about how the different choices impact debugging, performance, isolation, etc.