{"id":18292,"date":"2022-07-14T09:30:00","date_gmt":"2022-07-14T07:30:00","guid":{"rendered":"https:\/\/www.codemotion.com\/magazine\/?p=18292"},"modified":"2022-07-14T10:14:26","modified_gmt":"2022-07-14T08:14:26","slug":"ten-reasons-why-i-think-alpine-js-can-do-magic","status":"publish","type":"post","link":"https:\/\/www.codemotion.com\/magazine\/frontend\/ten-reasons-why-i-think-alpine-js-can-do-magic\/","title":{"rendered":"Ten Reasons Why I Think Alpine.js Can Do &#8220;Magic&#8221;"},"content":{"rendered":"\t\t\t\t<div class=\"wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-66520bcd      \"\n\t\t\t\t\tdata-scroll= \"1\"\n\t\t\t\t\tdata-offset= \"30\"\n\t\t\t\t\tstyle=\"\"\n\t\t\t\t>\n\t\t\t\t<div class=\"uagb-toc__wrap\">\n\t\t\t\t\t\t<div class=\"uagb-toc__title\">\n\t\t\t\t\t\t\tTable Of Contents\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<div class=\"uagb-toc__list-wrap \">\n\t\t\t\t\t\t<ol class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#1-its-an-html-enhancement-a-sort-of-declarative-jquery\" class=\"uagb-toc-link__trigger\">1 \u2013 It\u2019s an HTML enhancement &#8211; a sort of \u2018declarative jQuery\u2019<\/a><li class=\"uagb-toc__list\"><a href=\"#2-not-for-all-kinds-of-projects\" class=\"uagb-toc-link__trigger\">2- Not for all kinds of projects<\/a><li class=\"uagb-toc__list\"><a href=\"#3-alpinejs-makes-use-of-vues-reactivity-system\" class=\"uagb-toc-link__trigger\">3- Alpine.js makes use of Vue\u2019s reactivity system<\/a><li class=\"uagb-toc__list\"><a href=\"#4-alpinejs-is-built-with-the-proxy-pattern\" class=\"uagb-toc-link__trigger\">4- Alpine.js is built with the Proxy pattern<\/a><li class=\"uagb-toc__list\"><a href=\"#5-compared-to-front-end-vue-alpine-offers-a-fresher-way-to-make-things\" class=\"uagb-toc-link__trigger\">5- Compared to front-end Vue, Alpine offers a fresher way to make things<\/a><li class=\"uagb-toc__list\"><a href=\"#6-alpineeffect-allows-the-creation-of-dom-reactivity-via-a-jquery-esque-method\" class=\"uagb-toc-link__trigger\">6 \u2013 Alpine.effect allows the creation of DOM reactivity via a jQuery-esque method<\/a><li class=\"uagb-toc__list\"><a href=\"#7-using-livewire-you-get-a-full-stack-reactive-framework\" class=\"uagb-toc-link__trigger\">7- Using Livewire, you get a full-stack reactive framework<\/a><li class=\"uagb-toc__list\"><a href=\"#8-you-can-fetch-and-async-easily-with-alpine\" class=\"uagb-toc-link__trigger\">8- You can fetch and async easily with Alpine<\/a><li class=\"uagb-toc__list\"><a href=\"#9-x-if-and-x-show-are-different\" class=\"uagb-toc-link__trigger\">9 \u2013 x-if and x-show are different<\/a><li class=\"uagb-toc__list\"><a href=\"#10-alpine-is-extendible-in-a-cool-way\" class=\"uagb-toc-link__trigger\">10- Alpine is extendible, in a cool way<\/a><\/ol>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\n\n\n<p>When <strong>developing web applications<\/strong> I like to experiment with the capabilities of the tools the ecosystem has to offer, in order to find the most accurate solution for a particular project and to refine <strong>the coolest development stack possible<\/strong>. Every modern web development tool has specific potentials, limitations, and goals. <strong>The Alpine.js framework<\/strong> is one of the front-end tools that has most caught my interest; here are ten things I discovered while using this tool for web development.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-1-it-s-an-html-enhancement-a-sort-of-declarative-jquery\">1 \u2013 It\u2019s an HTML enhancement &#8211; a sort of \u2018declarative jQuery\u2019<\/h2>\n\n\n\n<p>Alpine.js is a pretty powerful <strong>front-end library <\/strong>that allows users to write responsive interfaces in declarative mode. Typically, Alpine is used to make static HTML templates interactive by augmenting and enhancing the HTML syntax via new directives and Javascript injection. <strong>I like to describe Alpine as a kind of \u2018declarative jQuery\u2019<\/strong> (or a modern replacement for jQuery with a Vue template taste), because it allows users to manipulate the DOM in a Vue-like way, but without the need for bundling and installation.<br><br>Of course you can install Alpine via NPM and import it into your bundle, <strong>making use of the full Alpine Javascript API<\/strong>, but for most projects, importing is made easy by injecting a simple, old-fashioned script derived from a CDN into your app.<br><br>Putting Alpine&#8217;s script in your &lt;head&gt; gives you the ability to manipulate the DOM in a declarative mode in just a few steps, and with a much shallower learning curve than tools like Angular, React, or Vue demand.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-2-not-for-all-kinds-of-projects\">2- Not for all kinds of projects<\/h2>\n\n\n\n<p>Alpine is a kind of layer on top of static HTML which enables reactive interactivity to be easily added.  Personally, I don&#8217;t see Alpine.js as a future competitor to the big three, but I don\u2019t think that\u2019s the authors&#8217; intention; <strong><a href=\"https:\/\/www.codemotion.com\/magazine\/frontend\/javascript\/5-javascript-frameworks-to-use-in-2022\/\" target=\"_blank\" aria-label=\"tools (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"ek-link\">tools<\/a> like React, Svelte, or Vue are complete development stacks<\/strong> allowing users to manage the web application in its entirety, while Alpine, as previously stated, is a <strong>tool for creating interactive front-end interfaces<\/strong>.<br><br> In my experience, not all projects need pachydermic, bulky tools like the big three listed, and it\u2019s precisely for the projects that don\u2019t need these tools that Alpine.js is most suitable. <br><br>Adding reactivity to a template in a simple and very powerful way <strong>without the need for bundles and back-end extensions<\/strong> &#8211; that\u2019s the Alpine.js tool in a nutshell.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-3-alpine-js-makes-use-of-vue-s-reactivity-system\">3- Alpine.js makes use of Vue\u2019s reactivity system<\/h2>\n\n\n\n<p>Once you\u2019re accustomed to Alpine&#8217;s way of making interactive data, you may think it&#8217;s a bit magical.<br><br>In reality, if you study the <strong>source code of any open-source tool<\/strong>, you\u2019ll find that the \u2018magic\u2019 is really very pragmatic. Reactivity in Alpine.js is caused by two main functions &#8211; Alpine.reactive () and Alpine.effect () &#8211; but if you take a look under the hood, <strong>these functions use VueJS&#8217;s reactivity engine<\/strong>. This engine is very powerful and can be used as a standalone, or with abstractions built on top of it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-4-alpine-js-is-built-with-the-proxy-pattern\">4- Alpine.js is built with the Proxy pattern<\/h2>\n\n\n\n<p>If you are interested in <strong><a href=\"https:\/\/www.geeksforgeeks.org\/types-of-software-architecture-patterns\/\" target=\"_blank\" aria-label=\"Design Pattern (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"ek-link\">Design Pattern<\/a> architectures<\/strong>, you may find it entertaining that in order to make the magic happen, the Alpine.reactive function makes use of the Proxy pattern.<br>A Proxy is basically a JavaScript object which allows you to wrap other objects, and to intercept and redefine operations on them. In a nutshell, Proxy objects make it possible to define objects that can be used in place of the original object, but which may redefine fundamental Object operations such as getting, setting, and defining properties, i.e.,&nbsp; by using a little bit of Javascript in order to better understand that:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">let<\/span> obj = { <span class=\"hljs-attr\">color<\/span>: \u2018blue\u2019 }\n<span class=\"hljs-keyword\">let<\/span> proxy = Alpine.reactive(obj)\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Here, the function <strong>Alpine.reactive receives a plain object and wraps it inside a Proxy object<\/strong>. The \u201cproxy\u201d variable is a wrapper around the \u201cobj\u201d variable, so any attempts to get or set a \u201cproxy\u201d property will behave exactly as if you had interacted with \u201cobj\u201d directly:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-built_in\">console<\/span>.log(obj.color) <span class=\"hljs-comment\">\/\/ blue<\/span>\n<span class=\"hljs-built_in\">console<\/span>.log(proxy.color) <span class=\"hljs-comment\">\/\/ blue<\/span>\n\nproxy.color = \u2018green\u2019\n \n<span class=\"hljs-built_in\">console<\/span>.log(obj.color) <span class=\"hljs-comment\">\/\/ green<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Now, any time you update or retrieve a value from the proxy object, <strong>Alpine is aware of this and can run any other logic<\/strong> that depends on this data.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-5-compared-to-front-end-vue-alpine-offers-a-fresher-way-to-make-things\">5- Compared to front-end Vue, Alpine offers a fresher way to make things<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2022\/04\/cover_infoArtboard-1-1024x576.png\" alt=\"Infographic, codemotion, playlists, languages, tools for developers\" class=\"wp-image-17636\" srcset=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2022\/04\/cover_infoArtboard-1-1024x576.png 1024w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2022\/04\/cover_infoArtboard-1-300x169.png 300w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2022\/04\/cover_infoArtboard-1-768x432.png 768w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2022\/04\/cover_infoArtboard-1-1536x864.png 1536w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2022\/04\/cover_infoArtboard-1-896x504.png 896w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2022\/04\/cover_infoArtboard-1-400x225.png 400w, https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2022\/04\/cover_infoArtboard-1.png 1920w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Alpine feels fresh to work with.<\/figcaption><\/figure>\n\n\n\n<p>There are many similarities between Alpine and (front-end) Vue, however, <strong>I personally find the Alpine approach a more comfortable option for developing interfaces<\/strong> &#8211;&nbsp; and it\u2019s a bit cooler as a development experience.<br><br>For example:<br>1- in Alpine (in most cases) you do not need a &lt;template&gt; wrapper<br>2- Alpine allows you to wrap component data directly in HTML, enhancing its functionalities (no need for separation of concerns):<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">div x-data = <span class=\"hljs-string\">\"{isOpen: false}\"<\/span>&gt;\n<span class=\"xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">button<\/span> <span class=\"hljs-attr\">x-on:click<\/span> =<span class=\"hljs-string\">\"isOpen = !isOpen\"<\/span>&gt;<\/span>Toggle<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">button<\/span>&gt;<\/span><\/span>\n<span class=\"xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h1<\/span> <span class=\"hljs-attr\">x-show<\/span> = <span class=\"hljs-string\">\"isOpen\"<\/span>&gt;<\/span>Alpine.js HTML enhancement!<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h1<\/span>&gt;<\/span><\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>3- if you\u2019re worried about separation of concerns and you want to reuse your component logic, this is possible without the need for export logic, a \u201cmethod\u201d object, or returning a data() wrapper:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">component1Data<\/span>(<span class=\"hljs-params\"><\/span>) <\/span>{\n  <span class=\"hljs-keyword\">return<\/span> {\n    <span class=\"hljs-attr\">isOpen<\/span>: <span class=\"hljs-literal\">false<\/span>,\n    toggleOpen() { <span class=\"hljs-keyword\">this<\/span>.isOpen = !<span class=\"hljs-keyword\">this<\/span>.isOpen }\n  }\n}\n&lt;div x-data = <span class=\"hljs-string\">\"component1Data()\"<\/span>&gt;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-6-alpine-effect-allows-the-creation-of-dom-reactivity-via-a-jquery-esque-method\">6 \u2013 Alpine.effect allows the creation of DOM reactivity via a jQuery-esque method<\/h2>\n\n\n\n<p>You can make powerful use of the second reactivity-maker function of Alpine &#8211; Alpine.reactive &#8211; which makes any data reactive. This works in combination with the previous reactivity maker:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">let<\/span> obj = { <span class=\"hljs-attr\">color<\/span>: \u2018blue\u2019 }\n<span class=\"hljs-keyword\">let<\/span> proxy = Alpine.reactive(obj)\n \nAlpine.effect(<span class=\"hljs-function\"><span class=\"hljs-params\">()<\/span> =&gt;<\/span> {\n    <span class=\"hljs-built_in\">console<\/span>.log(proxy.color)\n})\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>With this approach, the callback will be executed once, and whenever you interact with the reactive \u201ccolor\u201d property of the proxy object you will console.log its value.<br>This means you <strong>can skip the Alpine-HTML template completely<\/strong> and rely on vanilla Javascript DOM manipulations and the two Alpine reactivity-maker functions:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">let<\/span> button = <span class=\"hljs-built_in\">document<\/span>.querySelector(<span class=\"hljs-string\">'button'<\/span>)\n<span class=\"hljs-keyword\">let<\/span> span = <span class=\"hljs-built_in\">document<\/span>.querySelector(<span class=\"hljs-string\">'span'<\/span>)\n \n<span class=\"hljs-keyword\">let<\/span> proxy = Alpine.reactive({ <span class=\"hljs-attr\">color<\/span>: \u2018blue\u2019 })\n \nAlpine.effect(<span class=\"hljs-function\"><span class=\"hljs-params\">()<\/span> =&gt;<\/span> {\n    span.textContent = proxy.color\n})\n \nbutton.addEventListener(<span class=\"hljs-string\">'click'<\/span>, () =&gt; {\n    proxy.color = (proxy.color == \u2018blue\u2019) ? \u2018green\u2019 : \u2018blue\u2019\n}) \n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This feels to me like a fresh, yet powerful combination of <strong>imperative-declarative paradigm<\/strong> and a jQuery-Vue approach to doing things.<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-7-using-livewire-you-get-a-full-stack-reactive-framework\">7- Using Livewire, you get a full-stack reactive framework<\/h2>\n\n\n\n<p>It\u2019s no secret that I love Laravel, and I like Livewire too. Alpine.js seems to me to be a perfect companion for Livewire, producing results that resemble the full-stack React\/Vue experience of <strong>making web applications using a PHP environment<\/strong>. You can do many pretty amazing things with these two pieces of code straight out of the box &#8211; the most basic option is the interaction between a server-state and a front-end template:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">Obj1<\/span> <span class=\"hljs-keyword\">extends<\/span> <span class=\"hljs-title\">Component<\/span>\n<\/span>{\n    <span class=\"hljs-keyword\">public<\/span> $color = \u2018blue\u2019;\n \n    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">toggle<\/span><span class=\"hljs-params\">()<\/span>\n    <\/span>{\n        <span class=\"hljs-keyword\">$this<\/span>-&gt;color = ( <span class=\"hljs-keyword\">$this<\/span>-&gt;color == \u2018blue\u2019 ) ? \u2018green\u2019 : \u2018blue\u2019;\n    }\n}\n&lt;div&gt;\n    \n    &lt;div x-data&gt;\n        &lt;h1 x-text=<span class=\"hljs-string\">\"$wire.color\"<\/span>&gt;&lt;\/h1&gt;\n \n        &lt;button x-on:click=<span class=\"hljs-string\">\"$wire.toggle()\"<\/span>&gt;Toggle color&lt;\/button&gt;\n    &lt;\/div&gt;\n&lt;\/div&gt;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Because the $wire variable also uses a JavaScript Proxy under the hood, users can access properties and call methods on it, with those operations forwarded to Livewire.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-8-you-can-fetch-and-async-easily-with-alpine\">8- You can fetch and async easily with Alpine<\/h2>\n\n\n\n<p>Although Alpine is not designed as a native full-stack interaction tool, asynchronous operations that involve fetching data from a server are very common, and also very important from a templating perspective.&nbsp; <strong>You can fetch data very easily directly in the Alpine template<\/strong> &#8211; either by explicitly marking a function handler as async, or the opposite. In the latter case, Alpine will do the work for you:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">async <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">getItems<\/span><span class=\"hljs-params\">()<\/span> <\/span>{\n    let response = await fetch(<span class=\"hljs-string\">'\/api\/items\/all'<\/span>)\n    let json = await response.json()\n    <span class=\"hljs-keyword\">return<\/span> json\n}\n\n&lt;div x-text=<span class=\"hljs-string\">\"JSON.stringify(getItems())\"<\/span>&gt;&lt;\/div&gt;\n\n<span class=\"hljs-keyword\">or<\/span> alternatively:\n&lt;div\n    x-data=<span class=\"hljs-string\">\"{\n        items: {},\n\n        async getItems() {\n            this.items = await (await fetch('\/api\/items\/all')).json();\n        }\n    }\"<\/span>\n    x-init=<span class=\"hljs-string\">\"getItems\"<\/span>&gt;\n&lt;\/div&gt;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-9-x-if-and-x-show-are-different\">9 \u2013 x-if and x-show are different<\/h2>\n\n\n\n<p>This is quite a simple, but key concept: Alpine.js shines when it comes to toggle elements, a very common operation in making every frontend template.&nbsp; Here you have two ways of doing this: the x-show and x-if directives. <strong>They may look similar, but they are actually very different.<br><\/strong>First of all, the x-show directive \u2018hides\u2019 or \u2018shows\u2019 a DOM element, i.e.,&nbsp; when you don\u2019t see the element, it\u2019s because its CSS display property is set to \u2018none\u2019, while x-if completely removes the element from DOM.<br><br>Secondly, because of this behaviour, the element (or a series of elements nested in the root element) you have to inject the x-if directly into a &lt;template&gt; wrapper rather than into the direct DOM element you want to toggle.<br><br>Finally, x-show supports transition toggling, meaning you can combine its functionalities with the x-transition directive, which you can\u2019t do with x-if. Here you have two distinct, powerful mechanisms which allow you to toggle template parts with full control over the operation.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-10-alpine-is-extendible-in-a-cool-way\">10- Alpine is extendible, in a cool way<\/h2>\n\n\n\n<p>You are not bound to the directives and functionalities you\u2019ll find in the Alpine core engine. Instead, users can extend that mechanism by using the Alpine.directive and Alpine.magic functions. The first of these allows you to make custom directives that can then be injected into the HTML template:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\">Alpine.directive('wrap', el =&gt; {\n    el.textContent = \u2018***\u2019 + el.textContent + \u2018***\u2019\n})\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">x-data<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">span<\/span> <span class=\"hljs-attr\">x-wrap<\/span>&gt;<\/span>Wrap this text! <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">span<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p> The second allows you to make magic properties and functions:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">Alpine.magic(<span class=\"hljs-string\">'alert'<\/span>, () =&gt; {\n    <span class=\"hljs-keyword\">return<\/span> subject =&gt; alert(subject)\n})\n&lt;button @click=<span class=\"hljs-string\">\"$alert('say hello!')\"<\/span>&gt;Alert  this element text content&lt;\/button&gt;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>","protected":false},"excerpt":{"rendered":"<p>When developing web applications I like to experiment with the capabilities of the tools the ecosystem has to offer, in order to find the most accurate solution for a particular project and to refine the coolest development stack possible. Every modern web development tool has specific potentials, limitations, and goals. The Alpine.js framework is one&#8230; <a class=\"more-link\" href=\"https:\/\/www.codemotion.com\/magazine\/frontend\/ten-reasons-why-i-think-alpine-js-can-do-magic\/\">Read more<\/a><\/p>\n","protected":false},"author":94,"featured_media":18298,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_editorskit_title_hidden":false,"_editorskit_reading_time":5,"_editorskit_is_block_options_detached":false,"_editorskit_block_options_position":"{}","_uag_custom_page_level_css":"","_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[6],"tags":[9907,9961],"collections":[],"class_list":{"0":"post-18292","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-frontend","8":"tag-frameworks","9":"tag-javascript","10":"entry"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.9 (Yoast SEO v27.5) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Ten Reasons Why I Think Alpine.js Can Do &quot;Magic&quot; - Codemotion<\/title>\n<meta name=\"description\" content=\"Read on to discover code examples, tips, and lessons learned by a pro front-end developer using the alpine.js framework\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.codemotion.com\/magazine\/frontend\/ten-reasons-why-i-think-alpine-js-can-do-magic\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Ten Reasons Why I Think Alpine.js Can Do &quot;Magic&quot;\" \/>\n<meta property=\"og:description\" content=\"Read on to discover code examples, tips, and lessons learned by a pro front-end developer using the alpine.js framework\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.codemotion.com\/magazine\/frontend\/ten-reasons-why-i-think-alpine-js-can-do-magic\/\" \/>\n<meta property=\"og:site_name\" content=\"Codemotion Magazine\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Codemotion.Italy\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-07-14T07:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-14T08:14:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2022\/07\/jackson-sophat-_t-l5FFH8VA-unsplash.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Riccardo Degni\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@CodemotionIT\" \/>\n<meta name=\"twitter:site\" content=\"@CodemotionIT\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Riccardo Degni\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/frontend\\\/ten-reasons-why-i-think-alpine-js-can-do-magic\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/frontend\\\/ten-reasons-why-i-think-alpine-js-can-do-magic\\\/\"},\"author\":{\"name\":\"Riccardo Degni\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#\\\/schema\\\/person\\\/6912e00a94efa41fb20e92ba1bb050fb\"},\"headline\":\"Ten Reasons Why I Think Alpine.js Can Do &#8220;Magic&#8221;\",\"datePublished\":\"2022-07-14T07:30:00+00:00\",\"dateModified\":\"2022-07-14T08:14:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/frontend\\\/ten-reasons-why-i-think-alpine-js-can-do-magic\\\/\"},\"wordCount\":1376,\"publisher\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/frontend\\\/ten-reasons-why-i-think-alpine-js-can-do-magic\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/jackson-sophat-_t-l5FFH8VA-unsplash.jpg\",\"keywords\":[\"Frameworks\",\"JavaScript\"],\"articleSection\":[\"Frontend\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/frontend\\\/ten-reasons-why-i-think-alpine-js-can-do-magic\\\/\",\"url\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/frontend\\\/ten-reasons-why-i-think-alpine-js-can-do-magic\\\/\",\"name\":\"Ten Reasons Why I Think Alpine.js Can Do \\\"Magic\\\" - Codemotion\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/frontend\\\/ten-reasons-why-i-think-alpine-js-can-do-magic\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/frontend\\\/ten-reasons-why-i-think-alpine-js-can-do-magic\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/jackson-sophat-_t-l5FFH8VA-unsplash.jpg\",\"datePublished\":\"2022-07-14T07:30:00+00:00\",\"dateModified\":\"2022-07-14T08:14:26+00:00\",\"description\":\"Read on to discover code examples, tips, and lessons learned by a pro front-end developer using the alpine.js framework\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/frontend\\\/ten-reasons-why-i-think-alpine-js-can-do-magic\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/frontend\\\/ten-reasons-why-i-think-alpine-js-can-do-magic\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/frontend\\\/ten-reasons-why-i-think-alpine-js-can-do-magic\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/jackson-sophat-_t-l5FFH8VA-unsplash.jpg\",\"contentUrl\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/jackson-sophat-_t-l5FFH8VA-unsplash.jpg\",\"width\":1920,\"height\":1080,\"caption\":\"alpine.js framework, code smells\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/frontend\\\/ten-reasons-why-i-think-alpine-js-can-do-magic\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Frontend\",\"item\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/frontend\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Ten Reasons Why I Think Alpine.js Can Do &#8220;Magic&#8221;\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#website\",\"url\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/\",\"name\":\"Codemotion Magazine\",\"description\":\"We code the future. Together\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#organization\",\"name\":\"Codemotion\",\"url\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/wp-content\\\/uploads\\\/2019\\\/11\\\/codemotionlogo.png\",\"contentUrl\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/wp-content\\\/uploads\\\/2019\\\/11\\\/codemotionlogo.png\",\"width\":225,\"height\":225,\"caption\":\"Codemotion\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/Codemotion.Italy\\\/\",\"https:\\\/\\\/x.com\\\/CodemotionIT\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/#\\\/schema\\\/person\\\/6912e00a94efa41fb20e92ba1bb050fb\",\"name\":\"Riccardo Degni\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/rd-image-book-pic-e1697717445644-150x150.jpg\",\"url\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/rd-image-book-pic-e1697717445644-150x150.jpg\",\"contentUrl\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/rd-image-book-pic-e1697717445644-150x150.jpg\",\"caption\":\"Riccardo Degni\"},\"description\":\"I am a senior web developer, active both on front-end and back-end, a teacher focused on modern programming, a Research Consultant for IT research, and a writer who creates programming articles and guides. I am both a developer with a strong foundation in new technologies such as full Javascript-based environments and object-oriented programming on the server-side (PHP, Node, and Java), and a designer who makes powerful, modern, fully-responsive, and WordPress-free templates.\",\"sameAs\":[\"http:\\\/\\\/www.riccardodegni.com\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/riccardodegni\\\/\"],\"url\":\"https:\\\/\\\/www.codemotion.com\\\/magazine\\\/author\\\/riccardo-degni\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Ten Reasons Why I Think Alpine.js Can Do \"Magic\" - Codemotion","description":"Read on to discover code examples, tips, and lessons learned by a pro front-end developer using the alpine.js framework","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.codemotion.com\/magazine\/frontend\/ten-reasons-why-i-think-alpine-js-can-do-magic\/","og_locale":"en_US","og_type":"article","og_title":"Ten Reasons Why I Think Alpine.js Can Do \"Magic\"","og_description":"Read on to discover code examples, tips, and lessons learned by a pro front-end developer using the alpine.js framework","og_url":"https:\/\/www.codemotion.com\/magazine\/frontend\/ten-reasons-why-i-think-alpine-js-can-do-magic\/","og_site_name":"Codemotion Magazine","article_publisher":"https:\/\/www.facebook.com\/Codemotion.Italy\/","article_published_time":"2022-07-14T07:30:00+00:00","article_modified_time":"2022-07-14T08:14:26+00:00","og_image":[{"width":1920,"height":1080,"url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2022\/07\/jackson-sophat-_t-l5FFH8VA-unsplash.jpg","type":"image\/jpeg"}],"author":"Riccardo Degni","twitter_card":"summary_large_image","twitter_creator":"@CodemotionIT","twitter_site":"@CodemotionIT","twitter_misc":{"Written by":"Riccardo Degni","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/ten-reasons-why-i-think-alpine-js-can-do-magic\/#article","isPartOf":{"@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/ten-reasons-why-i-think-alpine-js-can-do-magic\/"},"author":{"name":"Riccardo Degni","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/6912e00a94efa41fb20e92ba1bb050fb"},"headline":"Ten Reasons Why I Think Alpine.js Can Do &#8220;Magic&#8221;","datePublished":"2022-07-14T07:30:00+00:00","dateModified":"2022-07-14T08:14:26+00:00","mainEntityOfPage":{"@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/ten-reasons-why-i-think-alpine-js-can-do-magic\/"},"wordCount":1376,"publisher":{"@id":"https:\/\/www.codemotion.com\/magazine\/#organization"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/ten-reasons-why-i-think-alpine-js-can-do-magic\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2022\/07\/jackson-sophat-_t-l5FFH8VA-unsplash.jpg","keywords":["Frameworks","JavaScript"],"articleSection":["Frontend"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/ten-reasons-why-i-think-alpine-js-can-do-magic\/","url":"https:\/\/www.codemotion.com\/magazine\/frontend\/ten-reasons-why-i-think-alpine-js-can-do-magic\/","name":"Ten Reasons Why I Think Alpine.js Can Do \"Magic\" - Codemotion","isPartOf":{"@id":"https:\/\/www.codemotion.com\/magazine\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/ten-reasons-why-i-think-alpine-js-can-do-magic\/#primaryimage"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/ten-reasons-why-i-think-alpine-js-can-do-magic\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2022\/07\/jackson-sophat-_t-l5FFH8VA-unsplash.jpg","datePublished":"2022-07-14T07:30:00+00:00","dateModified":"2022-07-14T08:14:26+00:00","description":"Read on to discover code examples, tips, and lessons learned by a pro front-end developer using the alpine.js framework","breadcrumb":{"@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/ten-reasons-why-i-think-alpine-js-can-do-magic\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.codemotion.com\/magazine\/frontend\/ten-reasons-why-i-think-alpine-js-can-do-magic\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/ten-reasons-why-i-think-alpine-js-can-do-magic\/#primaryimage","url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2022\/07\/jackson-sophat-_t-l5FFH8VA-unsplash.jpg","contentUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2022\/07\/jackson-sophat-_t-l5FFH8VA-unsplash.jpg","width":1920,"height":1080,"caption":"alpine.js framework, code smells"},{"@type":"BreadcrumbList","@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/ten-reasons-why-i-think-alpine-js-can-do-magic\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.codemotion.com\/magazine\/"},{"@type":"ListItem","position":2,"name":"Frontend","item":"https:\/\/www.codemotion.com\/magazine\/frontend\/"},{"@type":"ListItem","position":3,"name":"Ten Reasons Why I Think Alpine.js Can Do &#8220;Magic&#8221;"}]},{"@type":"WebSite","@id":"https:\/\/www.codemotion.com\/magazine\/#website","url":"https:\/\/www.codemotion.com\/magazine\/","name":"Codemotion Magazine","description":"We code the future. Together","publisher":{"@id":"https:\/\/www.codemotion.com\/magazine\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.codemotion.com\/magazine\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.codemotion.com\/magazine\/#organization","name":"Codemotion","url":"https:\/\/www.codemotion.com\/magazine\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/","url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png","contentUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png","width":225,"height":225,"caption":"Codemotion"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/Codemotion.Italy\/","https:\/\/x.com\/CodemotionIT"]},{"@type":"Person","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/6912e00a94efa41fb20e92ba1bb050fb","name":"Riccardo Degni","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2023\/10\/rd-image-book-pic-e1697717445644-150x150.jpg","url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2023\/10\/rd-image-book-pic-e1697717445644-150x150.jpg","contentUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2023\/10\/rd-image-book-pic-e1697717445644-150x150.jpg","caption":"Riccardo Degni"},"description":"I am a senior web developer, active both on front-end and back-end, a teacher focused on modern programming, a Research Consultant for IT research, and a writer who creates programming articles and guides. I am both a developer with a strong foundation in new technologies such as full Javascript-based environments and object-oriented programming on the server-side (PHP, Node, and Java), and a designer who makes powerful, modern, fully-responsive, and WordPress-free templates.","sameAs":["http:\/\/www.riccardodegni.com\/","https:\/\/www.linkedin.com\/in\/riccardodegni\/"],"url":"https:\/\/www.codemotion.com\/magazine\/author\/riccardo-degni\/"}]}},"featured_image_src":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2022\/07\/jackson-sophat-_t-l5FFH8VA-unsplash-600x400.jpg","featured_image_src_square":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2022\/07\/jackson-sophat-_t-l5FFH8VA-unsplash-600x600.jpg","author_info":{"display_name":"Riccardo Degni","author_link":"https:\/\/www.codemotion.com\/magazine\/author\/riccardo-degni\/"},"uagb_featured_image_src":{"full":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2022\/07\/jackson-sophat-_t-l5FFH8VA-unsplash.jpg",1920,1080,false],"thumbnail":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2022\/07\/jackson-sophat-_t-l5FFH8VA-unsplash-150x150.jpg",150,150,true],"medium":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2022\/07\/jackson-sophat-_t-l5FFH8VA-unsplash-300x169.jpg",300,169,true],"medium_large":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2022\/07\/jackson-sophat-_t-l5FFH8VA-unsplash-768x432.jpg",768,432,true],"large":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2022\/07\/jackson-sophat-_t-l5FFH8VA-unsplash-1024x576.jpg",1024,576,true],"1536x1536":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2022\/07\/jackson-sophat-_t-l5FFH8VA-unsplash-1536x864.jpg",1536,864,true],"2048x2048":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2022\/07\/jackson-sophat-_t-l5FFH8VA-unsplash.jpg",1920,1080,false],"small-home-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2022\/07\/jackson-sophat-_t-l5FFH8VA-unsplash.jpg",100,56,false],"sidebar-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2022\/07\/jackson-sophat-_t-l5FFH8VA-unsplash-180x128.jpg",180,128,true],"genesis-singular-images":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2022\/07\/jackson-sophat-_t-l5FFH8VA-unsplash-896x504.jpg",896,504,true],"archive-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2022\/07\/jackson-sophat-_t-l5FFH8VA-unsplash-400x225.jpg",400,225,true],"gb-block-post-grid-landscape":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2022\/07\/jackson-sophat-_t-l5FFH8VA-unsplash-600x400.jpg",600,400,true],"gb-block-post-grid-square":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2022\/07\/jackson-sophat-_t-l5FFH8VA-unsplash-600x600.jpg",600,600,true]},"uagb_author_info":{"display_name":"Riccardo Degni","author_link":"https:\/\/www.codemotion.com\/magazine\/author\/riccardo-degni\/"},"uagb_comment_info":0,"uagb_excerpt":"When developing web applications I like to experiment with the capabilities of the tools the ecosystem has to offer, in order to find the most accurate solution for a particular project and to refine the coolest development stack possible. Every modern web development tool has specific potentials, limitations, and goals. The Alpine.js framework is one&#8230;&hellip;","lang":"en","_links":{"self":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/18292","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/users\/94"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/comments?post=18292"}],"version-history":[{"count":12,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/18292\/revisions"}],"predecessor-version":[{"id":18408,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/18292\/revisions\/18408"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/media\/18298"}],"wp:attachment":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/media?parent=18292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/categories?post=18292"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/tags?post=18292"},{"taxonomy":"collections","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/collections?post=18292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}