sciactive / pnotify

Beautiful JavaScript notifications with Web Notifications support.
https://sciactive.com/pnotify/
Apache License 2.0
3.65k stars 514 forks source link

How to get existing notice options in PNotify 5? #421

Closed evolross closed 2 days ago

evolross commented 3 days ago

In the older versions of PNotify you could call...

PNotify.notices.find(function(notice) {
   //  Access to notice options like...
   notice.options.type === ...;
   notice.options.title === ...;
   notice.options.text === ...;
});

...in order to do comparisons of existing notices. We used a pattern like the above to make a createSingletonNotification() function.

Calling stack.forEach(function(notice) {...}) returns the notices but they now have limited functions for accessing their options.

Why has all this been removed from the API? For some odd reason, it seems like all we get is a way to check a notice's DOM containers which don't even have unique ids but just the same classes which requires getting them from the DOM manually and doing a bunch of work to their type, title, etc.

evolross commented 2 days ago

Figured it by finding this down in the Svelte code. Though not well documented, you can simply access a notice's attributes directly, like so:

stack.forEach(function(notice) {
   //  Access to notice options like...
   notice.type === ...;
   notice.title === ...;
   notice.text === ...;
});