Magic helpers to deal with timed functions:
Run a function repeatdly, after a given amount of time. It exposes the following properties:
Property | Type | Description |
---|---|---|
setup() |
function |
Used start a new execution (aborts the previous) |
abort() |
function |
Used to abort the execution |
Run a function after a given amount of time. It exposes the following properties:
Property | Type | Description |
---|---|---|
setup() |
function |
Used start a new execution (aborts the previous) |
abort() |
function |
Used to abort the execution |
As script tag, include the <script>
tag in the <head>
of your document just before Alpine:
<script src="https://cdn.jsdelivr.net/npm/alpinejs-toolkit/dist/timing/cdn.min.js" defer></script>
As module:
import Alpine from 'alpinejs';
import Timing from 'alpinejs-toolkit/timing';
Alpine.plugin(Timing);
Alpine.start();
The $every
helper accepts:
- An amount of time (in milliseconds)
- A function to be execute
<div x-data="$every(1000, () => console.log('Hello world!'))"></div>
The $after
helper accepts:
- An amount of time (in milliseconds)
- A function to be execute
<div x-data="$after(3000, () => console.log('Hello world!'))"></div>