News for hackers. Stuff that matters.
Re:The broken promise of Web Components by jondubois on Wednesday March 15, 2017 @05:20PM (#13879886)
Yes, it's like with JavaScript itself, it had some issues in the past, all the big issues were resolved but the stigma is still there.

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).

Re:The broken promise of Web Components by 31h on Wednesday March 15, 2017 @10:51PM (#13882050)
> JavaScript itself, it had some issues in the past, all the big issues were resolved

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.

Re:The broken promise of Web Components by Roboprog on Thursday March 16, 2017 @11:49AM (#13886005)
Possibly embrace the fact that semicolons are noise, and treat JS like you would Ruby or other line oriented languages??? (ignoring the fact that JS will "look ahead" past an otherwise complete line - e.g. - return [nothing] followed by open curly brace - but Ruby for example won't)

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 :-(

Re:The broken promise of Web Components by 31h on Thursday March 16, 2017 @12:31PM (#13886366)
> Possibly embrace the fact that semicolons are noise, and treat JS like you would Ruby or other line oriented languages???

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.

Re:The broken promise of Web Components by bigmanwalter on Wednesday March 15, 2017 @06:59PM (#13880718)
The React documentation says it so it has to be true. DOM slow, VDOM fast. Facebook is out there buying developer mindshare.
Re:The broken promise of Web Components by danabramov on Thursday March 16, 2017 @06:57AM (#13884010)
We don't claim that in React documentation. React can't be faster than the same DOM mutations written by hand because by definition it has to do more work.

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.

Re:The broken promise of Web Components by bigmanwalter on Thursday March 16, 2017 @08:37AM (#13884487)
I just haven't been able to figure out what, exactly, it is about manual DOM mutations that makes an app unmaintainable. As long as your code is organized and modular, it's always been easy enough for me to navigate through and maintain a non-React codebase.
Re:The broken promise of Web Components by danabramov on Thursday March 16, 2017 @11:20AM (#13885719)
I found these things hard:

* 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.

Re:The broken promise of Web Components by just2n on Thursday March 16, 2017 @07:12PM (#13889987)
Seconded on all counts. We also ended up independently implementing a really simplistic and in many ways broken version of React for these reasons and many others.
Re:The broken promise of Web Components by jbergens on Thursday March 16, 2017 @08:52AM (#13884563)
Probably finding the right place of the dom to change and keeping track of what to change. React basically says "make it like this" and takes care of a lot of things.

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.

Re:The broken promise of Web Components by bigmanwalter on Thursday March 16, 2017 @09:03AM (#13884630)
It's quite simple to handle that situation with jQuery and modules. If many parts of you code need to make a change to the DOM in the same place, you wrap the DOM changing in a module.

  var widget = require('./widget');
  widget.foo('bar');
And the widget handles the jQuery'ing for you.

  module.exports = {
    foo: function(s) { $('.widget').text(s) }
  }
Re:The broken promise of Web Components by dmitriid on Thursday March 16, 2017 @02:54PM (#13887901)
Only:

- 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)

Re:The broken promise of Web Components by just2n on Thursday March 16, 2017 @03:36PM (#13888403)
In my experience it's the needed complexity added by bookkeeping and the coupling that requires to do rendering/updates and data binding using manual DOM manipulations in a performant way, especially in larger scale apps. You can easily write maintainable and simple applications that manipulate the DOM directly if you don't care about performance, or in some cases correctness, and you'll quickly do worse than React would, from what I've seen.
Re:The broken promise of Web Components by kbenson on Wednesday March 15, 2017 @07:50PM (#13881038)
> Yes, it's like with JavaScript itself, it had some issues in the past, all the big issues were resolved but the stigma is still there.

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.

Re:The broken promise of Web Components by jdmichal on Thursday March 16, 2017 @03:19PM (#13888199)
As far as I know, `typeof` works on everything, but for Objects will only yield "object". You then should use `instanceof` to determine the type of object, if necessary. Typically, once I know it's an object I just use it, so that people can provide "non-traditional" but otherwise valid implementations. Only exception is if I'm specifically looking for a Date or DOM Node or other built-in type.

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.

Re:The broken promise of Web Components by comex on Wednesday March 15, 2017 @08:50PM (#13881390)
A somewhat more succinct option could be to coerce to Object and then use instanceof: 'Object(x) instanceof String'. Or you could use Object.getPrototypeOf, which coerces to Object automatically these days. But null and undefined are special: calling Object on them returns {}, and calling Object.getPrototypeOf on them throws.

If the type you're testing for is not one of the builtin literal types, you can just use instanceof.

Re:The broken promise of Web Components by kbenson on Thursday March 16, 2017 @04:34PM (#13888923)
"Object(foo) instanceof Class" does seem to be the most definitive, but unfortunately seems to require specific testing against a literal that must exist or it throws, and doesn't work for null/undefined. That at least brings the things I need to know to check the type of something down to three, two of which are singular special cases (if somewhat common ones), so that's better and possibly adequate, if not what I would consider good. Then again, I'm not sure I'm capable of thinking it could achieve good while there exists both an undefined and null in the language. It still boggles my mind that it has both.
Re:The broken promise of Web Components by comex on Thursday March 16, 2017 @05:48PM (#13889522)
To clarify, by "literal that must exist or it throws" you mean that you don't know whether the class you're testing for exists? Testing against an invalid class would be an error in most languages…

I guess an alternative is foo.constructor and foo.constructor.name, which will give you a string if you want that.

Re:The broken promise of Web Components by kbenson on Friday March 17, 2017 @04:24AM (#13892403)
Since many different js libraries may be loaded from many different sources, I could envision a situation where some utility functions may want to support different inputs depending on what's passed in, and what's passed in might depend on what's loaded, and what's loaded can change at runtime.

That's why many dynamic languages allow access to the type through a string representation.

Re:The broken promise of Web Components by Roboprog on Thursday March 16, 2017 @11:55AM (#13886054)
Not really. Also, typeof doesn't work at all on object literals.

Best just to see if it quacks, or barks :-)

(i.e. - does the object define a given function/"method")

Re:The broken promise of Web Components by skocznymroczny on Thursday March 16, 2017 @09:11AM (#13884678)
except it still doesn't have support for modules in 2017.