Skip to content
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

Method addEvent bug #124

Closed
IndyHendrickx opened this issue May 13, 2023 · 4 comments
Closed

Method addEvent bug #124

IndyHendrickx opened this issue May 13, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@IndyHendrickx
Copy link

IndyHendrickx commented May 13, 2023

I have encountered an issue with the addEvent method in my code. Here is the code snippet that I am using:

let data = [{ start: "2023-05-13 10:00", end: "2023-05-13 16:00", id: "1", isRegistered: "1", title: "Hello world" }, { start: "2023-05-11 12:00", end: "2023-05-11 13:00", id: "1", isRegistered: "0", title: "Hello world update?" }];

 // Add events if not already present
            for (var i = 0; i < data.length; i++) {
                // Check if event already exists
                if (calendar.getEventById(data[i].id)) {
                    // Update event by id
                    calendar.updateEvent({
                        start: data[i].start,
                        end: data[i].end,
                        resourceId: 1,
                        title: data[i].title,
                        color: "#779ECB",
                        id: data[i].id
                    })
                } else {
                    // Add new event
                    calendar.addEvent({
                        start: data[i].start,
                        end: data[i].end,
                        resourceId: 1,
                        title: data[i].title,
                        color: "#779ECB",
                        id: data[i].id
                    });
                }
            }
            console.log(calendar.getOption("events"));
            console.log(calendar.getEvents());

When I run this code, I expect the getEventById method to return the event that I just added with the ID '1' (when adding data index 1!). However, this is not working as expected. After adding all events to the calendar, I attempted to print the events for the calendar instance. However, calendar.getEvents() returns an empty array, even though the getOption("events") method shows that the events were added to the options.

It seems like the addEvent method is only adding the events to the DOM and the events property of the calendar instance. I appreciate any help or guidance on this issue. Thank you for the hard work put into this project, it is really impressive!

@vkurko vkurko added the bug Something isn't working label May 15, 2023
@vkurko
Copy link
Owner

vkurko commented May 15, 2023

@IndyHendrickx Thanks for reporting the bug. This behavior is due to some optimizations, when the internal event storage is updated not in the main task, but in the microtask. I'll provide a fix a.s.a.p.

@IndyHendrickx
Copy link
Author

@IndyHendrickx Thanks for reporting the bug. This behavior is due to some optimizations, when the internal event storage is updated not in the main task, but in the microtask. I'll provide a fix a.s.a.p.

@vkurko thank you so much! In the main time I have worked around this problem, by writing this helper function:

function findEvent(calendar, id) {
    return calendar.getOption("events").find(o => o.id === id);
}

So take your time to provide a fix, coding in a hurry is never good! And again, thank you for all the hard work!

@vkurko
Copy link
Owner

vkurko commented May 15, 2023

This should be fixed in v1.1.1. Please check.

@vkurko
Copy link
Owner

vkurko commented May 17, 2023

I hope I can close this issue.

@vkurko vkurko closed this as completed May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants