8000 Updated main file by OblackatO · Pull Request #10 · mlcheng/js-toast · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Updated main file #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Updated main file #10

wants to merge 1 commit into from

Conversation

OblackatO
Copy link

In my project I use a global variable to handle toasts. Basically, only one toast can exist at a time. So it is enough to have only one variable. When new toasts are created, something like the following happens:

var current_toast = ""
function item_ajoute_toast(item_name){
    const toast_options = {
        style: {
            main: {
                background: "green",
                color: "black",
            },
        },
        settings: {
            duration: 1500,
        },
    };
    if(current_toast !== null && current_toast !== "undefined" && current_toast !== ""){
        current_toast.hide()
    }
    current_toast = iqwerty.toast.toast(item_name+ ' ajouté!', toast_options);
}

Where current_toast, is the global variable. If current_toast is not undefined or null, then it exists and must be hidden so that next toast can be displayed. That is why there is the condition:

if(current_toast !== null && current_toast !== "undefined" && current_toast !== ""){
        current_toast.hide()
}

However, this causes a problem when the duration of the toast has faded. For instance, if the duration of some toast X is 2500, and if some other toast is displayed after that duration, hide() is called on a none existing object, and three errors occur. I provided patches for that in the exact places where those errors occur.

If a toast is displayed after X, but the duration of X is within 2500, that is fine. Basically, because X has not yet faded and the method hide() can safely be called.

I hope this explanation was clear :p

Added support for global toast variable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0