-
-
Save bennadel/fff91abd66e1cbea5bdb0aea13ec662c to your computer and use it in GitHub Desktop.
Magic Life-Cycle Test In Alpine.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<body> | |
<h1> | |
Custom Magic Life-Cycle Test In Alpine.js | |
</h1> | |
<div x-data="{ isShowing: false }"> | |
<button @click="( isShowing = ! isShowing )"> | |
Toggle | |
</button> | |
<template x-if="isShowing"> | |
<section> | |
<div x-text="( $kablamo + $kablamo )"></div> | |
<div x-text="( $kablamo + $kablamo )"></div> | |
</section> | |
</template> | |
</div> | |
<script type="text/javascript" src="../vendor/alpine.3.13.5.js" defer></script> | |
<script type="text/javascript"> | |
document.addEventListener( | |
"alpine:init", | |
function setupAlpineBindings() { | |
Alpine.magic( "kablamo", KablamoMagic ); | |
} | |
); | |
var magicID = 0; | |
/** | |
* I define the Kablamo magic handler. | |
*/ | |
function KablamoMagic( element, framework ) { | |
var id = ++magicID; | |
console.log( "Magic setup:", id ); | |
framework.cleanup( | |
() => { | |
console.log( "Magic cleanup:", id ); | |
} | |
); | |
return `[ Magic ${ id } ]`; | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment