News for hackers. Stuff that matters.
Re:Why we needed Redux in the past, and don’t any more by TekMol on Friday September 07, 2018 @03:10AM (#17932411)

    Most things that people build
    don't need anything like this.
True. It would be great to show examples of websites that benefit from the complexity of an extra library to handle client side state. I would think less then 1% do.

For example, lets look at how HN handles state syncing. Function "toggle" in this file handles collapsing/expanding threads:

https://news.ycombinator.com/hn.js

    function toggle (ev, id) {
      var on = !afind($(id), collapsed());
      (on ? addClass : remClass)($(id), 'coll');
      recoll();
      if ($('logout')) {
        new Image().src = 'collapse?id=' + id + (on ? '' : '&un=true');
      }
      ev.stopPropagation();
      return false;
    }
How would the react+redux approach look like? Is it really worth it?
Re:Why we needed Redux in the past, and don’t any more by k_ on Friday September 07, 2018 @03:21AM (#17932456)
React+redux (or just react) doesn't add much to websites. Maybe Vue.js would be a better fit when some complexity is needed in a website.

I see React as a tool for building web applications, not websites. Using it for something like hacker news is not needed nor worth it, except for learning purposes or for the sake of using your favorite tech (which has its pros and cons).

Edit: I use React a lot, and really like it. It's just not the perfect tool for everything, and by no means a necessary one (at least when you don't have much complexity); even if it is a good one in many cases.

In the case of HN, seeing the current js [1] I find it pretty obvious that no "big tool" like React is necessary. It doesn't mean using React for a HN clone is a bad thing, one just don't have to.

[1]: https://news.ycombinator.com/item?id=17915560&goto=news

Re:Why we needed Redux in the past, and don’t any more by eropple on Friday September 07, 2018 @03:30AM (#17932495)
Once you're using React for a web app, the cognitive load is not that high to use it to blam out a site, too. And it need not be slow or heavy, either; the website I'm currently working on uses React for rendering (both server-side and not, but it took me about an hour to get server-side rendering working for something where the very minimal state is only presentational) and has about a 60KB-gzipped JavaScript+CSS+images bundle all-told. (Of that, React is 5KB. Woo?)

I could use Vue, but I'm already using and continuing to use React, and I'm good enough at (what isn't actually) my job (because I'm no frontend developer, this is just what I do on the side) to minimize its impact on end users.

I also use React for fully static sites via Gatsby, though I don't love it, and to quickly build HTML mail templates. Granted, the bigger value here for me is JSX rather than React, but for my use cases they're functionally the same thing, and I do think you can get a lot out of using it. Especially if elsewhere in the stack you're already undertaking more complexity with it.

Re:Why we needed Redux in the past, and don’t any more by derekperkins on Friday September 07, 2018 @12:24PM (#17935540)
If you don't love Gatsby, you could try out https://github.com/nozzle/react-static
Re:Why we needed Redux in the past, and don’t any more by eropple on Saturday September 15, 2018 @07:35PM (#17996564)
I've looked at that too, but to be honest I find it confusing. :/
Re:Why we needed Redux in the past, and don’t any more by mattmanser on Friday September 07, 2018 @05:24AM (#17932923)
Just to echo expand on TekMol's reply as he's been downvoted for perhaps being too curt, but the distinction's essentially worthless as most web applications don't need the complexity of a big js framework either. When he says websites, he means web dev in general, no distinction necessary.
Re:Why we needed Redux in the past, and don’t any more by TekMol on Friday September 07, 2018 @03:23AM (#17932467)
In my book, "website" and "web application" are equivalent.

How do you define those terms?

Re:Why we needed Redux in the past, and don’t any more by k_ on Friday September 07, 2018 @03:26AM (#17932480)
I don't define them precisely either. I'll borrow an answer from stack overflow [1]:

This is totally personal and subjective, but I'd say that a website is defined by its content, while a web application is defined by its interaction with the user. That is, a website can plausibly consist of a static content repository that's dealt out to all visitors, while a web application depends on interaction and requires programmatic user input and data processing.

For example, a news site would be a "website", but a spreadsheet or a collaborative calendar would be web "applications". The news site shows essentially the same information to all visitors, while the calendar processes individual data.

Practically, most websites with quickly changing content will also rely on a sophisticated programmatic (and/or database) backend, but at least in principle they're only defined by their output. The web application on the other hand is essentially a program that runs remotely, and it depends fundamentally on a processing and a data storage backend.

[1]: https://stackoverflow.com/a/8694944/7510753

Re:Why we needed Redux in the past, and don’t any more by mattmanser on Friday September 07, 2018 @05:12AM (#17932871)
Most web applications don't need a JS framework either, so the distinction's actually worthless.
Re:Why we needed Redux in the past, and don’t any more by eropple on Friday September 07, 2018 @03:34AM (#17932511)
Web applications have interactive functionality as their focus. Websites have the consumption of what a human, and not an HTML parser, would call a "document": video, text, and images. They may not be statically served, but their code exists to facilitate the serving of what are recognizably documents.

Wordpress's backend is a web application. That web application exists to drive the website that is its frontend. Not really a controversial standpoint, I don't think, except amongst the hyper-literal who but-for about comment features (hence the use of "focus" above).

Re:Why we needed Redux in the past, and don’t any more by devilshaircut on Friday September 07, 2018 @03:26AM (#17932477)
Imo, not all websites are web apps. You can certainly still create a static website using just HTML. The term "app" to me implies functionality beyond the presentational.
Re:Why we needed Redux in the past, and don’t any more by JamesBarney on Friday September 07, 2018 @03:48AM (#17932557)
The guy who builds your website has never heard of big O.
Re:Why we needed Redux in the past, and don’t any more by KyeRussell on Friday September 07, 2018 @08:39PM (#17938724)
I build content driven websites as part of my job (not my favourite part by any means). I’ve most certainly “heard of Big O” - something they teach you in the first year of any university-level computing course.

Don’t be a dick.

Re:Why we needed Redux in the past, and don’t any more by JamesBarney on Tuesday September 18, 2018 @04:51PM (#18019000)
I wasn't being a dick, most designers and people who bill themselves out as website creators come from a creative background instead of a development background. For every 12 website creators I know with a photography/art/graphic design background, I only know one with a C.S. background.
Re:Why we needed Redux in the past, and don’t any more by eithed on Friday September 07, 2018 @05:17AM (#17932893)
JS can follow MVC / OO model. Simply most people don't try to do it and go with functional approach; add to this simplicity JS can be diven into, and you get the results we get where people cry that JS (jQuery) gives unmaintainable code. Reactive libraries try to address the issue by forcing you to create OO components and (to a degree) MVC patterns.
Re:Why we needed Redux in the past, and don’t any more by jahewson on Friday September 07, 2018 @03:35AM (#17932515)
That’s easy, it’s <Thread/> plus a bunch of code that I’ve omitted :p