masmerise / livewire-toaster

Beautiful toast notifications for Laravel / Livewire.
MIT License
374 stars 22 forks source link

Toaster from javascript #2

Closed oliverbj closed 1 year ago

oliverbj commented 1 year ago

Hi.

How can I trigger toasts from plain javascript, like:

//app.js
import './bootstrap';
import Alpine from 'alpinejs';
import focus from '@alpinejs/focus';
import Toaster from '../../vendor/masmerise/livewire-toaster/resources/js';

window.Alpine = Alpine;
Alpine.plugin(focus);
Alpine.plugin(Toaster);
Alpine.start();
//...

this.on("success", function(file, response) {
    Toaster.success('success message');
});

I get this error:

Toaster.success is not a function

mabdullahsari commented 1 year ago

The Toaster.success is not referring to what you think it's referring to within this particular scope.

Toaster here is the Alpine plugin, which is not what you want.

Use window.Toaster or globalThis.Toaster to access the global Toaster singleton.