angular-ui / ui-calendar

A complete AngularJS directive for the Arshaw FullCalendar.
http://angular-ui.github.io/ui-calendar/
MIT License
1.49k stars 729 forks source link

Event is not removed #210

Open floydqwz opened 9 years ago

floydqwz commented 9 years ago

I have problems with events not being removed from the calendar.

My event sources look something like this initially:

$scope.eventSources = [ [], [ev1, ev2], [] ];

I change one of the eventSources like this:

$scope.eventSources[1] = [ev1];

ev2 still remains though. Why does this happen?

floydqwz commented 9 years ago

If I in FullCalendar's removeEventSource remove all events not having a source set, the problem is solved. In the code below, notice the "e.source && " addition.

function removeEventSource(source) {
    sources = $.grep(sources, function(src) {
        return !isSourcesEqual(src, source);
    });
    // remove all client events from that source
    cache = $.grep(cache, function(e) {
        return e.source && !isSourcesEqual(e.source, source);
    });
    reportEvents(cache);
}

I suspect this is caused by me doing angular.copy() on my existing events if I get changes to them. So the same objects are kept but unknown properties like source, which FullCalendar adds, will be removed and set to undefined. So these events will hang free, unreferenced.

jediger commented 9 years ago

Thank you so much for this. Since "source" was being removed on save, I didn't even see it was there. My workaround was to save the source to a local variable and re-apply it after save. This seems to have fixed the issue I was having.

pgeyman commented 9 years ago

I have just come across this issue and after debugging I can narrow it down to the following function in UI-Calendar:

        eventsWatcher.onRemoved = function(event) {
          calendar.fullCalendar('removeEvents', function(e) { 
            return e._id === event._id;
          });
        };

In my project, the event object has no _id. Both objects do, however, have __uiCalId. So If I change the code as follows, it works:

        eventsWatcher.onRemoved = function(event) {
          calendar.fullCalendar('removeEvents', function(e) { 
            return e.__uiCalId === event.__uiCalId;
          });
        };
pgeyman commented 9 years ago

I see that a pull request has been submitted that removes the use of __uiCalId in favour of _id. So if that pull request is applied, then I guess this problem will go away without having to apply the above fix.

See pull request: https://github.com/angular-ui/ui-calendar/pull/248

joshkurz commented 9 years ago

@floydqwz @pgeyman can you check to see if this issue still persists?