It’s been awhile since I did any frontend work. Is there something that has taken jQuery’s place?

  • Max-P@lemmy.max-p.me
    link
    fedilink
    arrow-up
    50
    ·
    11 months ago

    It depends what you want to do and the amount of polyfills/backwards compatibility you need.

    Nowadays most projects use one of the big frameworks like React/Vue/Svelte and others which take a vastly different approach to maintaining the DOM and for the most part you never manipulate nodes yourself, therefore you don’t need jQuery and it’s not used much anymore. JSX is weird at first but it’s actually quite nice. Some of those libraries like SolidJS have impressively low overhead.

    And for those that like to stick to just minimal JS, the browser APIs have matured a lot so a lot of jQuery isn’t really necessary anymore either. We have querySelectorAll and things like Array.prototype.forEach and Array.prototype.map and arrow functions that cut down a lot on what shortcuts jQuery would offer. Visual effects are usually done with CSS animations and just switching up classes. Everything AJAX is easier and cleaner with the new fetch() function and accessories. Vanilla JavaScript is for the most part quite usable and easy these days. You can even create custom HTML elements from JavaScript to make your life easier!

    But if you’re looking at the jQuery API specifically, you can still use jQuery today. It’s still maintained and functional. I think modern versions are pretty small too since it no longer needs half of it to be Internet Explorer hacks and other obsolete browsers that were holding web development back.

      • realharo@lemm.ee
        link
        fedilink
        arrow-up
        4
        arrow-down
        2
        ·
        edit-2
        11 months ago

        Custom template language and custom DOM attributes are way weirder than just using language-native constructs (ternary operator, map/filter, variables, functions, etc.) directly like you can in JSX.

            • kameecoding@lemmy.world
              link
              fedilink
              arrow-up
              7
              ·
              edit-2
              11 months ago

              template syntax is a piece of cake, takes literally 2 hours to learn everything you need and you can easily see what’s where and how the html will look when it’s rendered or not.

              and the list rendering? you are literally pointing out the best features of vue.

              • realharo@lemm.ee
                link
                fedilink
                arrow-up
                2
                arrow-down
                2
                ·
                edit-2
                11 months ago

                But why bother with creating a new language, and duplicating all the features your language already has, in a weird way?

                If I want a list of UI items based on an array of some data, I can just do items.map(item => 〈Item key={item.id} item={item} /〉), using the normal map function that’s already part of the language.

                Or I can use a function, e.g. items.map(item => renderItem(item, otherData)) etc.

                JSX itself is a very thin layer that translates to normal function calls.

                • spartanatreyu@programming.dev
                  link
                  fedilink
                  arrow-up
                  4
                  ·
                  11 months ago

                  But why bother with creating a new language

                  I can just do items.map(item => 〈Item key={item.id} item={item} /〉)

                  I don’t think this is a very good example. You’ve just said not to use a new language, then used JSX, a new language.

                • kameecoding@lemmy.world
                  link
                  fedilink
                  arrow-up
                  2
                  ·
                  edit-2
                  11 months ago

                  but how do you know what renderItem does? where will the items end up?

                  we are visual creatures.

                  if I see a <ul><li></li></ul> I know it’s doing a list item for every object in given list.

                  it’s literally just html with a few added stuff, v-if to determine whether it’s rendered, v-for for iteration, dynamic class bindings and event listener bindings.

                  templating has also been around for a while for a reason it’s solid tech, thymeleaf and jsf/primefaces being prime examples.

                  • realharo@lemm.ee
                    link
                    fedilink
                    arrow-up
                    1
                    ·
                    edit-2
                    11 months ago

                    Well you don’t have to place it in a separate function, nothing stops you from inlining that part and writing li or whatever directly there.

                    It’s up to you how you organize your components.

        • spartanatreyu@programming.dev
          link
          fedilink
          arrow-up
          2
          ·
          edit-2
          11 months ago

          DOM attributes are built for browsers and frameworks to take advantage of.

          The style of some of those frameworks to stick symbols in there is downright weird. But that only goes against those particular frameworks. It doesn’t impact how good DOM attributes actually are.

        • spartanatreyu@programming.dev
          link
          fedilink
          arrow-up
          1
          ·
          edit-2
          11 months ago

          Svelte uses labels, so Svelte itself is weird compared to everything. Except in a way to assembly and 50s goto-control-flow styled code.

          • CmdrKeen@lemmy.today
            link
            fedilink
            arrow-up
            1
            ·
            11 months ago

            You mean these? Does it use them internally, because I haven’t really seen them in any Svelte code.

            If so, what does it matter what the compiler does in order to make your code work, so long as it’s legal? It’s perfectly valid JS, that’s all that counts.

            I wouldn’t say Svelte is weird as much as it’s different. That’s the whole point after all. Instead of adding a bunch of library bloat and keeping an entire copy of the DOM to constantly compare to and derive changes from, it compiles your components down to native JS that manipulates the DOM directly, like you would by hand. Except of course the compiler uses different ways to achieve that than you would, but that’s because it doesn’t have to care about readability, as long as it creates valid and efficient code.

      • DroneRights [it/its]@lemm.ee
        link
        fedilink
        English
        arrow-up
        1
        arrow-down
        2
        ·
        11 months ago

        Vue sucks. A pretty graphic of a CGI robot convincing untrained programmers to merge their web files and produce unreadable garbage as the output file.