0.1.1 • Published 4 years ago

@kevinbatdorf/alpine-auto-init v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

alpine-auto-init

A lightweight helper to auto call an init() method for Alpine.js

GitHub file size in bytes GitHub tag (latest by date)

About

Use this for when you want to auto initialize your AlpineJS instances using an init() function. Perfect when you don't need to use state.

<ul x-data="customBullets()">
  <li>One</li>
  <li>Two</li>
</ul>
function customBullets() {
  return {
    init() {
      for (let item of this.$el.children) {
        // Change list items
      }
    }
  }
}

Demo

Installation

Include the following <script> tag in the <head> of your document (before Alpine):

<script src="https://cdn.jsdelivr.net/gh/KevinBatdorf/alpine-auto-init@0.x.x/dist/index.js"></script>

Manual

If you wish to create your own bundle:

npm install KevinBatdorf/alpine-auto-init --save

Then add the following to your script:

import 'alpine-auto-init'
import 'alpinejs'

License

Copyright (c) 2020 Kevin Batdorf

Licensed under the MIT license, see LICENSE.md for details.