vrimar / construct-ui

A Mithril.js UI library
https://vrimar.github.io/construct-ui
MIT License
287 stars 23 forks source link

Timeout attribute not respected in Toaster().update() #24

Closed angrytongan closed 4 years ago

angrytongan commented 4 years ago

Using Toaster().update() with a new timeout doesn't change the time the toast appears.

Click the button 1 second, then 5 second. The toast updates, but the timeout doesn't.

const {
    Button,
    Toaster,

} = CUI;

const ToasterUpdate = () => {
    const toaster = new Toaster();
    const toasterMessages = [
        { name: '1 second',     message: '1 second timeout', timeout: 1000 },
        { name: '2 seconds',    message: '2 second timeout', timeout: 2000 },
        { name: '5 seconds',    message: '5 second timeout', timeout: 5000 },
    ];
    const getToast = (name) => toasterMessages.find((t) => t.name == name);

    return {
        view: () => {
            return [
                toasterMessages.map((tm) => m(Button, {
                    label: tm.name,
                    onclick: () => {
                        const existing = toaster.getToasts();

                        if (existing.length > 0) {
                            toaster.update(existing[0].key, getToast(tm.name));
                        } else {
                            toaster.show(getToast(tm.name))
                        }
                    }
                })),
                m(toaster),
            ];
        },
    };
};

document.addEventListener('DOMContentLoaded', () => {
    m.route(document.body, '/', {
        '/': ToasterUpdate
    });
});
vrimar commented 4 years ago

Fixed in v0.2.4.