News for hackers. Stuff that matters.
Re:How I converted my React app to VanillaJS by oelmekki on Monday January 02, 2017 @08:21AM (#13300987)
This is a very sane exercice to do, while obviously not something to recommend for production code - but I guess it's not the point.

We often take our tools for granted, without thinking about how they were designed. Doing such exercice allows both to get insights into the possible solutions for a problem one of our tools solves (allowing us to understand our tools better), and also is proper training for architecturing our own tools.

Thanks for sharing your discoveries.

Re:How I converted my React app to VanillaJS by Semiapies on Monday January 02, 2017 @11:29AM (#13302073)
And thanks for presenting it as an exploration and not the, "I am a real carpenter, so I don't use a hammer, I just pound in nails with my dick!" inanity a lot of these articles are.
Re:How I converted my React app to VanillaJS by tjallingt on Monday January 02, 2017 @06:49AM (#13300606)
Interesting read, although the shtick got a bit old near the end. I really wonder how this compares to inferno.js as that has some real optimisation magic to make it super small and super fast while also being, close to, compatible with React.
Re:How I converted my React app to VanillaJS by ieatkittens on Monday January 02, 2017 @03:56AM (#13299940)
Nice work. Enjoyed the step by step process. Want to do something similar, but in an Elm style.

A fun read as well.

Re:How I converted my React app to VanillaJS by tomcam on Monday January 02, 2017 @06:10AM (#13300474)
Can someone explain this interesting snippet?

  const h1 = () => makeElement(`h1`);
Re:How I converted my React app to VanillaJS by teniutza on Monday January 02, 2017 @06:30AM (#13300546)
It Uses "fat arrow" functions (lambdas) to define function. It is "equivalent" (there are several differences here, like "const" and the context of the function) to:

   var h1 = function() {
     return makeElement(`h1`);
   }
Edited to reflect the valid point brought up in the comments
Re:How I converted my React app to VanillaJS by drdaeman on Monday January 02, 2017 @07:28AM (#13300767)
Not really an equivalent, because "this" would be different - unlike with function(){}, there is no automatic this-context binding with arrows, so just switching to a fancier syntax in existing code may break things.

Also, no "arguments" (there are ...rest parameters that allow for variadic functions).

Re:How I converted my React app to VanillaJS by divbit on Monday January 02, 2017 @11:25AM (#13302034)
> no automatic this-context binding with arrows,

I thought the arrows were now binding to surrounding context? (e.g. https://babeljs.io/blog/2015/06/07/react-on-es6-plus)

Re:How I converted my React app to VanillaJS by nicoburns on Monday January 02, 2017 @11:30AM (#13302084)
It is equivalent in this case though, as the function body doesn't use any of those features...
Re:How I converted my React app to VanillaJS by closetnerd on Monday January 02, 2017 @06:56AM (#13300627)
Techinically you're missing a return.
Re:How I converted my React app to VanillaJS by tomcam on Monday January 02, 2017 @06:42AM (#13300585)
Ah, thanks a ton. Everything I looked up was too general to help!
Re:How I converted my React app to VanillaJS by k__ on Monday January 02, 2017 @06:12AM (#13300483)
before you have to write

    makeElement(`h1`)
everywhere

after this declaration you can write

    h1()
instead

just a shortcut function

Re:How I converted my React app to VanillaJS by tomcam on Monday January 02, 2017 @06:30AM (#13300545)
Sorry, it was the syntax up to the makeElement(`h1`); that I didn't understand:

  const h1 = () =>
Is this new syntax declaring a function named h1 that returns a function or what? I don't understand what the empty pair of parentheses means.
Re:How I converted my React app to VanillaJS by k__ on Monday January 02, 2017 @06:43AM (#13300588)
Yes, this is a shortcut for:

    const h1 = function() {
      return makeElement('h1');
    }
Arrow functions without arguments need empty paranthesis.

They also have an implicit return if you don't use {}

Re:How I converted my React app to VanillaJS by pluma on Monday January 02, 2017 @07:17AM (#13300722)
To add to the other explanations: it's also important to point out that arrow functions are slightly different from regular functions in that they don't redefine `arguments` and `this` so these keywords behave like any other variable would in a closure.

So it's not just a syntactic shorthand but there's also a semantic difference.

Re:How I converted my React app to VanillaJS by teniutza on Monday January 02, 2017 @06:37AM (#13300568)
Yes, it's ES6/ES2015. It's a lambda function ("fat arrow notation"). In the parentheses you would specify the arguments. An empty pair of parentheses means that the function does not expect any parameters.
Re:How I converted my React app to VanillaJS by tomcam on Monday January 02, 2017 @06:43AM (#13300590)
OK, thanks. So it is the parameter list, not the return value
Re:How I converted my React app to VanillaJS by mattnewton on Monday January 02, 2017 @10:16AM (#13301542)
This is declaring a constant and assigning a function that takes no arguments to that constant.
Re:How I converted my React app to VanillaJS by jmkni on Monday January 02, 2017 @09:41AM (#13301341)
This post reminds me of the book, Build your own AngularJS

It's a little old now, but still worth a read.

https://teropa.info/build-your-own-angular/

Re:How I converted my React app to VanillaJS by nenadg on Monday January 02, 2017 @08:46AM (#13301112)
Creating frameworks by reversing the works of others is something I'd call art. I really enjoyed your article, and I'll surely use some of it for a personal framework that I'm currently writing.

Great work.

Re:How I converted my React app to VanillaJS by kelvin0 on Monday January 02, 2017 @12:53PM (#13302866)
TL;DR : Even though ReactJS (or any other JS framework) is 'heavy', Web Devs still need them to be able to code in a sane way for real world products.
Re:How I converted my React app to VanillaJS by vladimir-y on Monday January 02, 2017 @02:02PM (#13303479)
Correct. Self made framework is a good thing for pet projects and in terms of education. But if you work in a team on the long-term project it's better to use standard tools since there will be a need to expand the team and it's better new members are already aware of the used tools/frameworks.
Re:How I converted my React app to VanillaJS by pitaj on Monday January 02, 2017 @03:12AM (#13299764)
More like, "How I wrote my own framework in VanillaJS"
Re:How I converted my React app to VanillaJS by k__ on Monday January 02, 2017 @06:24AM (#13300527)
Doesn't code automatically look like a framework when you structure it?
Re:How I converted my React app to VanillaJS by hwh on Monday January 02, 2017 @11:03AM (#13301852)
You can e.g. hide that fact within a DSL!
Re:How I converted my React app to VanillaJS by ralfn on Monday January 02, 2017 @02:51PM (#13303849)
Thats just called software engineering.

Its not a bad thing when 95% of the code in your project is borrowed (i.e. when you use a framework), but ducktaping stuff together will only get you so far.

For the size of the example project (single dev, one day, single page) and the requirements (load as fast as possible) this would be the superior approach. React would indeed be overkill. And below 200ms load times has proven impact on conversions. That is: the requirement is realistic and commercially, if at all possible, not at all negotiable.

Re:How I converted my React app to VanillaJS by drivingmenuts on Monday January 02, 2017 @08:42PM (#13305991)
I guess I'm NOT the only person not sold on React/Angular. Unfortunately, all the companies hiring in my area are. :(
Re:How I converted my React app to VanillaJS by yoz-y on Tuesday January 03, 2017 @04:45AM (#13308043)
At the end of the article the author admits that while this is a worthy exercise and might sometimes be useful, using a framework such as react does have a lot of benefits.
Re:How I converted my React app to VanillaJS by fleetfox on Monday January 02, 2017 @03:36AM (#13299847)
"replacement" - not even close.