News for hackers. Stuff that matters.
Re:2016 JavaScript Rising Stars by ng12 on Wednesday January 18, 2017 @02:15PM (#13429365)
> You can just put it on the page and voila, you have observables, computed properties, templates, everything. No webpack, no transpiling, no modules, no npm.

This is a false dichotomy. React is a fully-featured, standalone library and functionally equivalent to Vue if all you include is react.min.js. You don't need webpack or npm, you don't need Redux or MobX. This attitude stems from people learning React from create-react-app (which is geared towards a fully-featured, multi-developer, production-ready application) without doing FB's TodoMVC or even reading the React docs.

Re:2016 JavaScript Rising Stars by brilliantcode on Wednesday January 18, 2017 @04:48PM (#13430600)
I don't think you can ignore the relative less amount of pain associated with Vue.js over React.js.

It's just easier to get started with Vue.js and I'm just tired of the constant marketing campaign from Facebook...guess what 99.9% of companies out there aren't facebook or google.

The relative ease to get into Vue.js and it's fast growing popularity are signs that it's hitting the right pain points with developers who don't work at Facebook.

Re:2016 JavaScript Rising Stars by spion on Wednesday January 18, 2017 @05:53PM (#13431223)
The thing is, in any real project where you need a front-end framework, you will need modules very soon. And once you need modules, you need a bundler, which means you need a build process. While you are building, you might as well take advantage of neat ES.next / TypeScript features such as decorators, as well as maybe type-checking for JSX templates, and so on.

This is the reason why I always choose React.

(Well, that, and the huge existing ecosystem, and fact that components are first class in the template language e.g. you can pass a component as a parameter to a template and you can bring components into scope by importing them. But those are fairly advanced features)

Re:2016 JavaScript Rising Stars by nailer on Thursday January 19, 2017 @09:03AM (#13435794)
> The thing is, in any real project where you need a front-end framework, you will need modules very soon.

Sure, and modules are good even if you didn't need data binding at all. But the data binding and the module system you use are orthogonal and CommonJS/npm is still larger than any other module system by 10x, maybe 100x, maybe more.

Re:2016 JavaScript Rising Stars by spion on Thursday January 19, 2017 @10:27AM (#13436468)
Right. CommonJS is great, I actually like it more than ES6 modules. But even with CommonJS you still need the bundler and the build step.

You can get data binding in React with MobX, which pretty much gets you on par with Vue: https://mobx.js.org/getting-started.html . If you don't like how anemic setState is, and don't like the boilerplate / straightjacket of Redux, MobX is the way to go.

Admittedly, React's simpler options are harder to find :)

Re:2016 JavaScript Rising Stars by flukus on Wednesday January 18, 2017 @09:42PM (#13432519)
> The thing is, in any real project where you need a front-end framework, you will need modules very soon.

Only if you go the SPA route.

Re:2016 JavaScript Rising Stars by spion on Thursday January 19, 2017 @04:43AM (#13434419)
No, only if you plan on writing any reusable components. Which is sort of the point of any framework.

Well, unless you plan on writing all your code in one file (likely painful), or using an async loader (either slow, or painful because of manually managing dependencies and load order).

Re:2016 JavaScript Rising Stars by flukus on Thursday January 19, 2017 @04:10PM (#13439523)
We had reusable components long before SPAs, but each individual page is largely unique anyway.
Re:2016 JavaScript Rising Stars by spion on Friday January 20, 2017 @12:14PM (#13445211)
Depends on what you see by "largely unique". Do you have a spinner while you wait for data to show up on each page? Then you might have a common spinner component.

Of course, you could also re-code the spinner every single time. Or you could use an existing library of components and then you don't have to deal with modules, only that library does.

Re:2016 JavaScript Rising Stars by flukus on Saturday January 21, 2017 @06:02PM (#13452572)
Easily done by including the component server side, either in the master page (for common things that are used everywhere) or the page itself. SPA's do literally nothing to componentize sites/apps that we couldn't do before.
Re:2016 JavaScript Rising Stars by spion on Sunday January 22, 2017 @06:24PM (#13458320)
How about components that you need twice on the page? Are you going to just include them and their JS twice? Or perhaps build an elaborate server-side module system, one in which components required multiple times are only included once at the end of the page with a script.
Re:2016 JavaScript Rising Stars by victormustar on Wednesday January 18, 2017 @06:57PM (#13431671)
And you have everyone of those with Vue too btw
Re:2016 JavaScript Rising Stars by spion on Wednesday January 18, 2017 @07:58PM (#13432027)
Not really.

You don't have typescript's typechecking for templates.

You don't have higher-order components or first class components. Scoped slots are almost there, but not quite.

Also, "scoped slots" show that vue's simplicity is a bit of an illusion. There is a lot of reinventing the wheel happening underneath to get templates to the basic level of modularity / encapsulation / features of plain old JS.

It was similar with Angular. "Look how simple it is!" - yeah, until you actually need to build something serious with it... then you need to learn 3 times as much as React and all its tooling.

Here is an exercise: Write a spinner component in vue that renders either a spinner, an error message, or any other component (must be passed to the spinner component as a parameter) to which you can pass the data of the fulfilled promise.

Here is a react implementation:

https://jsfiddle.net/mm145xkj/

You just write a component where you pass two props: a promise to monitor, and a function that will take the data of the fulfulled promise and use it to render anything.

How do you do that in Vue? Is it simpler than the React implementation?

Re:2016 JavaScript Rising Stars by eblanshey on Saturday January 21, 2017 @03:24AM (#13449365)
Nobody responded to you, so I took on your challenge :) I'm still pretty new to Vue, but after a while of fiddling I came to a pretty simple solution: https://jsfiddle.net/jsfiddle4ephi/6xLwgqxk/1/

IMO, this is more readable than React, especially if extracted to their own .vue components.

1. Upon a successful resolve, you can make it render props/data to a custom component.

2. You can put each of the component into their own vue files to make it super clean: https://vuejs.org/v2/guide/single-file-components.html

This was a fun challenge, thanks!

Re:2016 JavaScript Rising Stars by spion on Sunday January 22, 2017 @06:32PM (#13458368)
Nice try, but I expect that the template is contained within the app template (or really any other template), i.e. `<spinner promise=promise> <inner template parameterized on data here></spinner>`. I don't want to be passing raw html strings around.

I'm sure vue has some scoped slot template transclusion thing to solve it... actually scratch that, I'm not sure if the equivalent of plain old first class functions exist in its template language :)

Re:2016 JavaScript Rising Stars by spion on Monday January 23, 2017 @11:00AM (#13463053)
I also forgot:

Its not just about raw HTML: this might need to be a totally custom template with data bindings to other data. Here is an example, the spinner's promise provides the data for a dropdown component which in turn is bound to a member of the parent component's data.

The challenge does need some more work to make it more realistic :)

Re:2016 JavaScript Rising Stars by knowThySelfx on Friday January 20, 2017 @01:51AM (#13442106)
Exactly. I could easily get into Vue. But not to React. Perhaps its my plain js affinity speaking.
Re:2016 JavaScript Rising Stars by throwaw199ay on Wednesday January 18, 2017 @02:22PM (#13429439)
> This is a false dichotomy.

No, React beginner tutorial implies learning JSX , then you need to compile JSX into JS. Vue.js does none of that. You just write Javascript and HTML. And yes, Vue.js also supports server-side rendering.

Re:2016 JavaScript Rising Stars by ng12 on Wednesday January 18, 2017 @02:27PM (#13429492)
The argument is passing your source code through a REPL makes it significantly more difficult to learn? Learning JSX isn't any more difficult than learning Vue's template binding syntax.
Re:2016 JavaScript Rising Stars by BinaryIdiot on Wednesday January 18, 2017 @03:37PM (#13430064)
You're completely ignoring the argument. React doesn't really tell you that you can just grab that file but even so you still need to get JSX processed.

It's all about the friction. Vue currently offers significantly less friction to jump into than React.

Re:2016 JavaScript Rising Stars by nailer on Thursday January 19, 2017 @09:05AM (#13435802)
JS -> JSX is transpilation, not a REPL.
Re:2016 JavaScript Rising Stars by ng12 on Thursday January 19, 2017 @02:00PM (#13438485)
Yes, and the Babel REPL/CLI can do that transpilation.
Re:2016 JavaScript Rising Stars by nailer on Friday January 20, 2017 @08:48AM (#13443720)
One wouldn't normally use babel as a REPL. I don't think it even has one (asides from node's own REPL, which isn't normally part of using Babel). Have you ever interactively typed commands into Babel?
Re:2016 JavaScript Rising Stars by woogley on Wednesday January 18, 2017 @03:21PM (#13429946)
> React is ... functionally equivalent to Vue if all you include is react.min.js

Not really, you also need react-dom.min.js ;) But even then, Vue is sporting automatic reactive dependencies, computed properties, watchers, conditional class names, and other things without requiring a trip to some random NPM package. And it's still a smaller payload than react/react-dom

Re:2016 JavaScript Rising Stars by spion on Wednesday January 18, 2017 @05:59PM (#13431285)
Right. You need inferno-compat as a drop-in replacement for react, as well as mobx for all the other vue features.

The payload for that would be similar to vue: 15KB min+gzip for mobx + 7kB for inferno-compat + 4kb for mobx-react = 26KB min+gzip. Latest vue is also 26KB min+gzip