I am using Alpine JS store() to make a global function available to toggle a modal status.
Module:
export default () => ({
/**
* @property isOpen - controls the state of the Contact Form Modal
*/
isOpen: false,
open() {
this.isOpen = true
},
close() {
this.isOpen = false
},
});
Then I use it like:
import modalContactForm from './alpine/modal-contact-form';
// Alpine.store sets data for GLOBAL usage
Alpine.store('modalContactForm', modalContactForm);
Alpine.start();
And with this HTML:
<button x-data @click="$store.modalContactForm.open()"></button>
But I get:
Alpine Expression Error: $store.modalContactForm.open is not a function
And I don't know how to debug this situation.
Interestingly, if I pass the object directly into Alpine.store(), it works.
Alpine.store('modalContactForm', {
isOpen: false,
open() {
this.isOpen = true
},
close() {
this.isOpen = false
},
});
Alpine.start();