News for hackers. Stuff that matters.
Re:Removing jQuery from GitHub.com frontend by thermodynthrway on Wednesday July 25, 2018 @05:58PM (#17613282)
If you have even medium complexity you're better off using something like React with Babel or Typescript. Much more sane way of event handling than JQuery, and no mucking with HTML by hand.

I agree with JQuery for the most simple sites, but React+transpiler will give you much better compatibility

Re:Removing jQuery from GitHub.com frontend by EB66 on Thursday July 26, 2018 @03:13PM (#17620079)
It sounds like you're saying using jQuery and a modern component-ized front-end framework are mutually exclusive. jQuery and modern front-end components can go together very easily -- albeit not specifically with React and Vue.

Our company built an in-house front-end framework heavily inspired by React and Vue. The components built using the framework work with or without jQuery. No manual DOM manipulations, one-way data binding, sane state management, templating, etc. Many of us prefer to use jQuery because of how compact and expressive the syntax is.

It really surprises me how many people think that jQuery === old school manual DOM manipulations. It definitely doesn't have to be that way.

Re:Removing jQuery from GitHub.com frontend by ergo14 on Wednesday July 25, 2018 @06:20PM (#17613452)
Thing is react is only compatible with react ;-)
Re:Removing jQuery from GitHub.com frontend by thermodynthrway on Wednesday July 25, 2018 @06:49PM (#17613636)
It's extremely easy to use React in small parts of the page and spread it out over time. It's a couple lines of code to init React in a div and fully supported. You can even communicate between React bits spread across the page.

React also let's you mark areas/divs within its domain as "don't touch this". So in those areas you can use things like that old map widget you love so much, without resorting to iframes

Angular is a huge fail in this regard. Zero support for mixing with "non angular" pages.

Re:Removing jQuery from GitHub.com frontend by EugeneOZ on Thursday July 26, 2018 @03:14AM (#17615641)
All what you describe in this commentary is much more easy to implement with just jQuery. Your logic more looks like "I can do it with React so it means I should and I believe it's the best tool".
Re:Removing jQuery from GitHub.com frontend by girvo on Thursday July 26, 2018 @09:52AM (#17617476)
Until you’ve got some moderately complex state and infrastructure to handle it, where you end up recreating the whole State -> Render loop of React in jQuery. I recently did this. It works, well, and with less bugs than most hacky jQuery DOM modification, but by the end I was pining for any other modern view library that already solved this. Same reason I used to pine for jQuery on some projects.
Re:Removing jQuery from GitHub.com frontend by feverdream on Wednesday July 25, 2018 @07:40PM (#17613920)
Can you elaborate on this? In my limited experience with React, it takes over your whole application, or at least the whole page. How do you mark areas as "don't touch this"?
Re:Removing jQuery from GitHub.com frontend by kroltan on Wednesday July 25, 2018 @08:05PM (#17614060)
I'm not sure on the "don't touch this" part, but in regards to "taking over the application", it certainly doesn't.

React's entry point is the `ReactDOM.render` function, which takes some React elements, and a root node. that root node can be _any_ DOM node (Actually no idea if you can mount React into a inline SVG, but at least any _HTML_ node you certainly can). You can also have multiple `ReactDOM.render` calls, no problem at all.

That initial React element can very well take values and callbacks from your Angular or whatever application.

It can get messy if you nest `ReactDOM.render` within roots that are managed by React, but so would nesting any other UI framework, but the use cases for that are... Exuberantly exotic, to say the least.

Re:Removing jQuery from GitHub.com frontend by mhink on Thursday July 26, 2018 @12:04AM (#17614987)
So, the way to look at it is that you “mount” a React application at a specific part of the DOM. Anything under that point is managed by React components.

Usually, people have a single “mount point” very close to the <body> element, and a single script file whose primary purpose is to call ReactDOM.render to “mount” a React component representing their application at that point.

However, that doesn’t prevent you from having DOM outside that mount point, and it doesn’t prevent you from having code which does other things that don’t have anything to do with the React-managed part of the page. This is a great way to migrate a legacy application to React: you choose one small section of your page to replace with React, and then have the remainder of your page interact with it by 1.) choosing when to call ReactDOM.render again to ask it to update, and 2.) passing in callbacks so the React ”mini-app” can notify the rest of your application when something happens.

You can go the other way, too, although it’s a little less safe. If you have a React component which renders, say, a <div> with no children, you can get a handle to the DOM element itself and interact with it just like you would in a non-React application. The only constraint here is that you have to make sure to clean up e.g. event handlers and release references to those elements if something causes the “owner” React component to unmount. This is how people make wrapper libraries which let you use non-React-based libraries using React components. (I’ve done this in a side project where I had a huge number homogenous DOM elements to work with, and found that managing them myself was much more performant than trying to run them through React’s model.)

Re:Removing jQuery from GitHub.com frontend by disiplus on Thursday July 26, 2018 @03:04AM (#17615583)
i have something like that in one of my projects, there is "inbox" in one of my apps, it is handled with react, and the header, and top menu are outside of react and generated from backend. it works great. the only problem i had is in the developing, the thing that i did is i developed the inbox feature separately and then im copying the dist to my app on compile.
Re:Removing jQuery from GitHub.com frontend by thermodynthrway on Wednesday July 25, 2018 @08:17PM (#17614126)
I haven't had to do so much myself, but the docs have decent info on how to obtain it. https://reactjs.org/docs/integrating-with-other-libraries.ht...
Re:Removing jQuery from GitHub.com frontend by testvox on Wednesday July 25, 2018 @11:37PM (#17614899)
React components mount to any element you want. And everything they do will happen within that element if you are using react conventionally. There is no issue mounting components alongside/inside legacy apps.
Re:Removing jQuery from GitHub.com frontend by FLUX-YOU on Wednesday July 25, 2018 @07:36PM (#17613894)
Angular is a nightmare for complex UI interactions for components that are spread out.

I'm sure experienced people know how to do that properly, but it's really difficult starting out.

Re:Removing jQuery from GitHub.com frontend by thermodynthrway on Wednesday July 25, 2018 @08:20PM (#17614135)
Angular's learning curve is the worst I've ever seen. We mostly use it because "Enterprise" but I prefer React when we get permission for that reason.

Too much abstraction, too much magic. It's possible to do just about anything but the docs are sparse enough that you'll be crawling through github PR's and source to figure out how to achieve it sometimes

Re:Removing jQuery from GitHub.com frontend by EugeneOZ on Thursday July 26, 2018 @03:10AM (#17615617)
Angular is an amazing tool for building reusable components and interoperation between them is pretty easy to implement (just use "input/output" handlers). I'm not saying it just to say something opposite, it is really my opinion and it's what I do almost every day.
Re:Removing jQuery from GitHub.com frontend by skeoh on Wednesday July 25, 2018 @08:52PM (#17614283)
Can you elaborate on this? I've integrated React into Angular and Ember projects in the past with no compatibility issues.
Re:Removing jQuery from GitHub.com frontend by ergo14 on Thursday July 26, 2018 @03:11PM (#17620065)
Did the "foreign" elements stamp out react elements or interact with their properties?
Re:Removing jQuery from GitHub.com frontend by skeoh on Sunday July 29, 2018 @04:10AM (#17637064)
I tried not to have multiple frameworks controlling the same DOM elements. It would usually be a React component mounted to a DOM element controlled by a component in another framework.
Re:Removing jQuery from GitHub.com frontend by ergo14 on Wednesday August 01, 2018 @05:55AM (#17661065)
Exactly, that is my problem, if a react component state is altered by "outside world", weird things can happen. So you actually avoided interoperability between solutions.
Re:Removing jQuery from GitHub.com frontend by samueldavid on Wednesday July 25, 2018 @06:24PM (#17613480)
why not Vue?
Re:Removing jQuery from GitHub.com frontend by lucasmullens on Wednesday July 25, 2018 @06:35PM (#17613550)
"something like React" includes Vue.
Re:Removing jQuery from GitHub.com frontend by interlocutor on Wednesday July 25, 2018 @06:33PM (#17613537)
React is great for rendering (and updating after initial render), but if your app is highly interactive then jQuery makes things easier even when using React for rendering.
Re:Removing jQuery from GitHub.com frontend by thermodynthrway on Wednesday July 25, 2018 @06:45PM (#17613603)
You generally don't mix react and JQuery. The event system + JSX makes jQuery obsolete.

Having worked in complex interactive React/Angular apps as well as ones using JQuery, nobody would ever offer me enough to use JQuery again for this use case. They would have to double my pay for all the pain

Re:Removing jQuery from GitHub.com frontend by interlocutor on Wednesday July 25, 2018 @07:42PM (#17613943)
Show me a dropdown menu written in React and I'll show you how you can simplify the code significantly by using jQuery in addition to React.
Re:Removing jQuery from GitHub.com frontend by thermodynthrway on Wednesday July 25, 2018 @08:26PM (#17614167)
Development with React is becoming similar to old school event driven desktop apps, thankfully.

If I want a fancy drop-down with accessibility support and theming etc, there's probably 50 different libraries with components I can pull in and use with little fuss. A few lines of code to import and register event listeners.

I was a huge user of jQuery for years, and it also has quite nice UI libraries. But the power of React is the standardized scaffold and lifecycle. I can pull in UI components from almost any library and use them intuitively. Mix and match them on the same page.

Trying to do that in jQuery will quickly drag you to hell.

Re:Removing jQuery from GitHub.com frontend by mariusmg on Thursday July 26, 2018 @08:14AM (#17616794)
>Trying to do that in jQuery will quickly drag you to hell.

Can you elaborate on this please ? I've used lots of libraries with jquery and haven't encountered problems.

Re:Removing jQuery from GitHub.com frontend by thermodynthrway on Thursday July 26, 2018 @09:37AM (#17617358)
Easy to cause it by combining bootstrap components and JQueryUI.

In React you can "scope" a components CSS so none of the styling leaks out

Re:Removing jQuery from GitHub.com frontend by squiggleblaz on Wednesday July 25, 2018 @08:12PM (#17614091)
Can you be more concrete?

If you want some specific code to criticise, there's dozens of dropdown menu widgets available: here's one I found in Google https://github.com/react-component/menu since I've never actually had reason to use a js/html drop down menu widget.

Re:Removing jQuery from GitHub.com frontend by interlocutor on Wednesday July 25, 2018 @08:21PM (#17614144)
Here's one that uses jQuery. See how much simpler it is? The one you found does have more functionality, but try rewriting the one I found in React without using jQuery. I guarantee it will be much more complicated.

https://github.com/wisercoder/uibuilder/blob/master/SimpleDe...

Re:Removing jQuery from GitHub.com frontend by moretti on Thursday July 26, 2018 @04:31AM (#17615939)
It’s interesting that you find this “simpler”. One of the great advantages of React is that is declarative, it’s easy to understand how a component will render given a set of (props, state). Your example is quite the opposite, the render method violates this principle and each event handler manipulates the DOM using a ref. I’d call this spaghetti-React.
Re:Removing jQuery from GitHub.com frontend by petilon on Thursday July 26, 2018 @11:01AM (#17617997)
Did you miss the fact that this component is interactive? You can't do interactivity declaratively.
Re:Removing jQuery from GitHub.com frontend by moretti on Thursday July 26, 2018 @12:06PM (#17618510)
By declaratively I mean that in React you typically declare how an element should be render given the current (props, [state]).

For example, in vanilla JS, you might have something like:

  const btn = document.createElement('button');
  btn.className = 'btn red';
  btn.onclick = function(event) {
   if (this.classList.contains('red')) {
     this.classList.remove('red');
     this.classList.add('blue');
   } else {
     this.classList.remove('blue');
     this.classList.add('red');
   }
  };

In React instead:

  class Button extends React.Component {
    state = { color: 'red' }
    handleChange = () => {
      const color = this.state.color === 'red' ? 'blue' : 'red';
      this.setState({ color });
    }
    render() {
      return (<div>
        <button 
           className=`btn ${this.state.color}`
           onClick={this.handleChange}>
        </button>
      </div>);
    }
  }
I find it simpler to understand, because render, given its state, describes exactly how the UI should be.
Re:Removing jQuery from GitHub.com frontend by petilon on Saturday August 04, 2018 @08:12AM (#17686544)
This only works for simple cases. Where this breaks down is when you have to inspect the current state of the DOM before deciding what changes to make to it. Example: scroll an element into view if it is not already visible. More examples: drag & drop, interactive resize, etc.
Re:Removing jQuery from GitHub.com frontend by thermodynthrway on Wednesday July 25, 2018 @08:42PM (#17614241)
It's not about how complex the component is. In my experience what matters is how easy it is to use. With React it's easy to build a world in a teacup, and that's mostly a good thing.

For "regular CRUD developers", the vast majority of us, I have zero concern about how big or crazy component code is until it's so huge it impacts page size. I'll use the easiest most feature complete library out there.

React does encapsulation like jQuery never could. I don't care if I have this vanta black box on my page as long as it's easy to mess with and gets the job done

Re:Removing jQuery from GitHub.com frontend by Piskvorrr on Thursday July 26, 2018 @04:58AM (#17616046)
"I have zero concern about how big or crazy component code is until it's so huge it impacts page size." Me and my mobile browser would like to have a few words with you. Not everything that can execute JS is a supercomputer...performance still matters.
Re:Removing jQuery from GitHub.com frontend by interlocutor on Wednesday July 25, 2018 @08:58PM (#17614318)
You don't care if the code is significantly simpler by using jQuery? I do care. Simpler code is likely to have fewer bugs and is easier to maintain.
Re:Removing jQuery from GitHub.com frontend by thermodynthrway on Wednesday July 25, 2018 @09:22PM (#17614409)
I'm talking about my code specifically. With React I can pull in a massively complex UI component in few lines.

The complexity is shifted to the library that hopefully has thousands of users so is mostly bug free. It simplifies my code at the expense of moving complexity to the shared project. Much preffered since my code will see orders of magnitude less usage than the library itself

Re:Removing jQuery from GitHub.com frontend by j16sdiz on Thursday July 26, 2018 @02:11AM (#17615382)
I care debugibilty and maintainibility. Many projects on github have very short life cycle. If it go unmaintained, how easy can I take over it?
Re:Removing jQuery from GitHub.com frontend by thermodynthrway on Thursday July 26, 2018 @09:39AM (#17617374)
I would argue that most websites have a lifetime similar to the components :). For the ones that don't, backwards compatibility on the web is amazing, only thing to worry about is security vulns
Re:Removing jQuery from GitHub.com frontend by Cthulhu_ on Thursday July 26, 2018 @05:40AM (#17616191)
You're correct that simpler code is better, but here's my argument: Large jQuery applications are not simpler, have more bugs, are harder to maintain and have poorer performance than React applications.

jQuery is a DOM manipulation utility library. React is a view rendering library, favoring composition and isolated components.

Re:Removing jQuery from GitHub.com frontend by ben-schaaf on Thursday July 26, 2018 @05:20AM (#17616114)
What do you even need javascript for in a dropdown?
Re:Removing jQuery from GitHub.com frontend by KevanM on Thursday July 26, 2018 @08:01AM (#17616750)
How else are you going to add back in the accessibility you've broken by building it with JavaScript?
Re:Removing jQuery from GitHub.com frontend by petilon on Thursday July 26, 2018 @11:03AM (#17618011)
For filtering as you type?
Re:Removing jQuery from GitHub.com frontend by boubiyeah on Thursday July 26, 2018 @05:39AM (#17616185)
you are seriously mistaken about react then. The whole point of MV libs is that you maintain a model (domain and/or UI) and the UI just redraws itself. JQuery is 100% not needed even for the most complicated React apps.
Re:Removing jQuery from GitHub.com frontend by petilon on Thursday July 26, 2018 @11:12AM (#17618072)
When you have a highly interactive component you're going to need to make a lot of DOM calls to get the current state of the elements and so on. jQuery makes this easy. The benefits of jQuery over making raw DOM calls have been mentioned by many people here already, so I won't repeat them. These benefits of jQuery don't go away even in a React app.