Outils pour utilisateurs

Outils du site


informatique:javascript:alpinejs

Alpine.js

AlpineJs permet de créer/gérer des composants falicement avec Javascript sans se lancer dans une SPA, très léger (<10ko gzippé et minifié) et n'utilise pas de DOM virtuel. Sa syntaxe est similaire à VueJS. C'est un bon outil pour remplacer jQuery et moins complexe que VueJs / React / Angular.

Présentation des principes d'AlpineJs : https://codewithhugo.com/alpine-tips/

Comparaison avec Juris JS

Alpine.js Limitations:

  • Template-bound logic - Business logic mixed with HTML attributes
  • Debugging challenges - Hard to debug x-data and x-show in DevTools
  • No true islands - Global Alpine state affects entire page
  • Limited composability - Difficult to share logic between components
  • Opaque reactivity - Can't easily inspect state changes

Juris.js Advantages:

  • Pure JavaScript - All logic in debuggable JS functions
  • True islands - Each enhancement is completely isolated
  • Transparent state - Clear state management with full debugging support
  • Service injection - Clean dependency injection pattern
  • Selector targeting - Precise DOM targeting without attribute pollution

Tips

Select multiple

Version simple ; utilise directement l'event $event.target.selectedOptions :

<div class=&quot;mb-3&quot;>
 <label for=&quot;rirSelect&quot; class=&quot;form-label&quot;>Select RIR(s):</label>
 <select id=&quot;rirSelect&quot; class=&quot;form-select&quot; multiple
    @change=&quot;filterRirs($event.target.selectedOptions)&quot;>
  <template x-for=&quot;rir in guiData.rirs&quot; :key=&quot;rir.key&quot;>
   <option x-bind:value=&quot;rir.key&quot; x-text=&quot;rir.attributes.label&quot;></option>
  </template>
 </select>
</div>

Version avec bouton pour supprimer la sélection et désactiver ce bouton quand aucune sélection ; utilise un x-data :

<div class=&quot;mb-3&quot; x-data=&quot;{selectedOptions:[]}&quot;>
 <label for=&quot;rirSelect&quot; class=&quot;form-label&quot;>Select RIR(s):</label>
 <button class=&quot;btn btn-outline-primary btn-sm&quot;
   x-bind:disabled=&quot;selectedOptions.length==0&quot;
   @click=&quot;selectedOptions=[];filterRirs()&quot;
   >All</button>
 <select id=&quot;rirSelect&quot; class=&quot;form-select&quot; multiple
   x-model=&quot;selectedOptions&quot; @change=&quot;filterRirs(selectedOptions)&quot;
   >
  <template x-for=&quot;rir in guiData.rirs&quot; :key=&quot;rir.key&quot;>
   <option x-bind:value=&quot;rir.key&quot; x-text=&quot;rir.attributes.label&quot;></option>
  </template>
 </select>
</div>
informatique/javascript/alpinejs.txt · Dernière modification : de cyrille

Sauf mention contraire, le contenu de ce wiki est placé sous les termes de la licence suivante : CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki