top | item 12383386

Stepping Backwards from AngularJS to JQuery – An Experiment

36 points| pcote | 9 years ago |hundredminutehack.blogspot.com

67 comments

order

carsongross|9 years ago

Giving up Angular did force me to think more about the DOM. Vanilla jQuery doesn't insert itself as readily into HTML code as an Angular directive can.

And that's why you should use http://intercoolerjs.org for most of your stuff, and a bit of jQuery where necessary for more exotic UX needs. The people who got sick of a mess of jQuery code were right, but they went the wrong direction to fix it. We have to go back.

I know people get tired of my shilling, but intercooler really is a better way for many, and maybe most, web apps to be developed.

andybak|9 years ago

I am personally fully behind your shilling and try to shill on your behalf whenever possible. It's sad how little interest intercooler has managed to garner when it's a fantastic antidote to so many things that are wrong with client-side development.

I recently used a touch of intercooler on a Django project and it just felt so right. Once I'd included intercooler.js itself, everything else was done via normal http attributes. It felt clean and lightweight.

jordanlev|9 years ago

FYI, none of the code on your site works for me, possibly because I have cookies and localStorage disabled in my browser. Not sure if this is specific to your framework or a quirk of the website itself (hopefully not the whole framework, as I don't understand why this requirement would be imposed if not actually needed by the app that's using it... since the fundamental premise of the framework seems to be "it's lightweight").

Silhouette|9 years ago

Personally I welcome useful mentions of relevant alternatives in HN discussions, even if it's someone's own project.

I would encourage you to tone down your rhetoric a bit, though. Intercooler looks like a good lightweight tool for projects with lightweight requirements, but based on your own documentation, the claim that it covers most of what is needed for most modern web apps just hurts your credibility.

pseudosavant|9 years ago

I hadn't heard of intercooler.js but that looks pretty awesome. Definitely going to check it out.

rowanseymour|9 years ago

Appreciate the shill. Hadn't heard of intercooler, but looks very interesting. At our company we've recently been pondering whether to fully embrace the client heavy approach of frameworks like Angular - which we've found frustrating in many ways (mixing server and client templating, localization, duplicated validation logic etc). We've used PJAX in the past and this looks like a suitably modern replacement.

jsmith0295|9 years ago

I was actually just about to use jQuery + PJAX on a new project, but this looks much better! Perfect timing.

asciihacker|9 years ago

Intercooler.js is quite cool.

jasonkostempski|9 years ago

I think there's a better approach to handling the delete buttons that's pretty common when using jQuery. Instead of each button having it's own handler function I would specify an event handler on a single DOM element (e.g. a list container) with something like $('#itemlist').on('click', '.delete', deleteItem). When 'deleteItem' is called 'this' will be the clicked button element that could have an attribute like 'data-itemid=123' which you use to fill in the 'id' part of the service call. And from there, after a successful service call, you can usually get at the parent element you want to remove from the list and take just that out instead of refreshing the entire list.

EDIT: Had the 'on' parameters mixed up. Here's the api doc: https://api.jquery.com/on/

impostervt|9 years ago

I found this interesting because it seems to have been written by a person who learned Angular before jQuery. I haven't run into that before.

Maybe I'm getting old.

andybak|9 years ago

I found that odd. I do worry that many people use technologies because other people working at a completely different scale or in a completely different domain have hit a ceiling which wouldn't really apply to most people. They are convinced to start with a more complex and more difficult technology that's solving problems they are unlikely to be facing any time soon.

1. NoSQL <> traditional RDMS because of scaling/sharding

2. Angular <> jQuery (or anything similarly lightweight) because of the issues around huge complex webapps

3. 'Fast' languages <> 'nice' languages ( ;-) ) because of performance concerns

4. Static typing <> Dynamic typing because of maintainability across large teams.

5. Docker/Microservices etc <> traditional architectures because of... I really have no idea...

So I guess the degenerate case is some poor chap learning web development who decides to write their Pet Store as an angular app with a Scala API backed by Mongo and Solr deployed to a Kubernates cluster ;-)

niftich|9 years ago

This is a very good point; I also found the submission enlightening for that reason -- because of the 'rediscovery' of jQuery, and how for simple use-cases, it's actually fairly palatable.

All solutions go through a maturity cycle where we invent an ostensibly "better" way of doing it because we're frustrated with the old way -- jQuery came about because early DOM selectors were lacking, Angular came about because people built complicated client-side spaghetti code state machines with jQuery -- but eventually a new wave of people comes along and the 'new way' becomes the 'mainstream way', and the like.

Like this author has done, it's interesting to go back and rediscover how things were done in the past, and in many cases you learn more about the problem domain or your stack of choice by doing so. My age is also showing that Angular no longer counts as cutting-edge, early-adopter tech, but firmly in the camp of mainstream ways of doing client-side code.

bryanrasmussen|9 years ago

I have a suspicion that this kind of thing happens with programmers who have not worked much on client side development moving to it from Enterprise Java development or similar disciplines. This suspicion also seems to be borne out/hinted at by the post.

pcote|9 years ago

Nope. jQuery came first. For me, it was a matter of spending a few years in Java shops. Most of the work was so server-side focused that I ended up forgetting a lot of my Javascript.

After leaving my last job, I decided I needed to update my skills and Angular seemed like a good road to go down. It was only recently that I decided to return to the old jQuery well to see what I could do with it vs. Angular. I'm glad I did.

bdcravens|9 years ago

Well, I actually learned Angular 2 before I learned Angular 1.

jnbiche|9 years ago

Next time, try dropping jQuery, too, and just using vanilla JavaScript. Just for fun. Simple DOM manipulation is now as simple in vanilla JavaScript as jQuery, with the only big advantage jQuery has now is if you're animating. You may find you're not missing much. You'd have to get used to slightly more involved Ajax syntax, unless you can target only new browsers, in which case the `fetch` API is just as convenient as jQuery's Ajax.

Heck, if you can can transpile to ES6 or if you're only targeting new browsers, you could probably even drop the Handlebars in factor of template literals without losing too much convenience.

neogodless|9 years ago

http://vanilla-js.com/

"Vanilla JS is a fast, lightweight, cross-platform framework for building incredible, powerful JavaScript applications."

"In fact, Vanilla JS is already used on more websites than jQuery, Prototype JS, MooTools, YUI, and Google Web Toolkit - combined."

mattmanser|9 years ago

Using vanilla js is still a massive pita even with ES6.

Nowt's going to beat $(".thing") vs:

    document.getElementByClassNameWhichWordsDidIForgetToCapitalizeThisTimeManVanillaJavascriptSucks
Or

    document.querySelectorWhoopsNoIMeantQuerySelectorAllGodVanillaJavascriptSucks
Design by committee, you get crap. Ease of use is incredibly important. And don't even get me started on on the fly dom manipulation, vanilla js really sucks for that.

    let div = document.createElement("div");
    div.iMAlreadyBoredTyping = "Yes";
    node.appendChild(div);
vs

    $(node).append($("<div>").data("quick", 1"));

talmand|9 years ago

What's the big advantage of jQuery with animating? Are you referring to the animation built into jQuery?

pbreit|9 years ago

Caveat: novice programmer here.

Even Angular is still difficult for me to grok and sometimes I wonder if stuff that comes out of Google "suffers" (for me) from Google having unlimited resources and employing superior engineers? Would Google have a difficult time empathizing with "average" programmers with limited resources?

rajangdavis|9 years ago

I think Angular takes a considerable amount of time to wrap your head around. I think the largest issues that you will most likely run into is an ng-repeat with large collection of objects (which, due to dirty checking, may impact your site), memory leaking, and using multiple controllers or controller as syntax.

I used Mithril for a while and it opened up my eyes as far as thinking "functionally"; it makes your code easier to understand and extend.

If you use filters functionally with Angular, you can get great performance on large collections in a ng-repeat. Likewise, if you understand prototypical inheritance, it will make working with multiple controllers/states a lot easier.

I really enjoy developing Angular, but it took a lot of time to really process. jQuery just works out of the box, but for me, it feels like it is more for little snippets of codes across various pages. It just depends on what you are trying to do.

quantumhobbit|9 years ago

If angular were produced by superior engineers, it would be easier, not harder, for lesser engineers to grok it.

The problem is not with you, but with a those that made angular more complicated than it could have been.

ruraljuror|9 years ago

I think the reason Angular2 might be difficult for a novice programmer is because of the nature of problems it tries to solve. It is an MVC framework with an emphasis on dependency injection and test-driven development. A novice programmer probably has at most a limited understanding of MVC, dependency inversion, and TDD, so you would need to learn more about those concepts to even work through the tutorial. Taking that into account, in may or may not be the right tool for the job depending on the problem.

ariabuckles|9 years ago

I've run into a lot of people who found angular hard to pick up; it's not just you.

One of them now works on the React team, and I found it pretty easy to pick up from the official docs: https://facebook.github.io/react/ . I recommend not bothering with stuff other than the base react library at first (although jsx/babel is nice); you can use react without it and potentially learn that later.

It's also totally valid to just start with basic js/html/jquery. The Mozilla's MDN docs for most html/js things are decent, and jQuery's api docs are pretty good in my experience.

asciihacker|9 years ago

Angular is difficult to grok because it makes computer programming second class and limited to what you can cram into HTML tags.

Angular isnt really a Google product - Misko Hevery and another guy (both Google SW Engineers) developed in their free time.

Dart is a Google product and I would say is much easier to grok than Angular.

matchagaucho|9 years ago

Amazed at how Angular has created a generation of programmers that accept 2-way data binding and MVC as "the only way" to develop web apps.

JQuery encourages more fluent, purely functional reasoning, and one-way data binding of immutable data objects.

pcote|9 years ago

Functional, yes. I can't think of too many cases where JQuery has every prevented me from mutating anything.