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

add getEventSources and refetchEventSources methods to refetch specific event sources #3103

Closed
wants to merge 16 commits into from

Conversation

caseyjhol
Copy link
Contributor

@caseyjhol caseyjhol commented Mar 25, 2016

close #254
close #1328

Example here: http://embed.plnkr.co/6s2LGElJC7Fyy004cmUC/.

This example also includes getEventSources for the purpose of retrieving the event sources. In the example, when refetchEventSources is called, an array of refetched eventSource IDs are displayed below the calendar.

@espen
Copy link
Contributor

espen commented Mar 26, 2016

This is very useful. I think you should add some tests though.

@caseyjhol
Copy link
Contributor Author

Working on making some tests - something I don't have experience with yet. Currently, though, I'm getting errors even with the normal FullCalendar code (possibly fixed by #3101?)

@caseyjhol
Copy link
Contributor Author

@arshaw Any comments/suggestions?

@arshaw
Copy link
Member

arshaw commented Apr 14, 2016

what errors are you seeing?

@caseyjhol
Copy link
Contributor Author

caseyjhol commented Apr 18, 2016

@arshaw

I'm getting the following errors when running the automated tests out of the master branch:

Chrome 49.0.2623 (Windows 10 0.0.0) removeEventSource with a URL correctly removes events provided via `events` at initialization FAILED
        Expected 0 to be 2.
        Error: Expected 0 to be 2.
            at expectEventCnt (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/tests/automated/removeEventSource.js:108:33)
            at options.eventAfterAllRender (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/tests/automated/removeEventSource.js:61:6)
            at trigger (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/dist/fullcalendar.js:9275:25)
            at FC.View.Class.extend.trigger (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/dist/fullcalendar.js:7372:27)
        Expected 0 to be 2.
        Error: Expected 0 to be 2.
            at expectEventCnt (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/tests/automated/removeEventSource.js:109:57)
            at options.eventAfterAllRender (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/tests/automated/removeEventSource.js:61:6)
            at trigger (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/dist/fullcalendar.js:9275:25)
            at FC.View.Class.extend.trigger (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/dist/fullcalendar.js:7372:27)
Chrome 49.0.2623 (Windows 10 0.0.0) removeEventSource with a URL correctly removes events provided via `eventSources` at initialization FAILED
        Expected 0 to be 2.
        Error: Expected 0 to be 2.
            at expectEventCnt (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/tests/automated/removeEventSource.js:108:33)
            at options.eventAfterAllRender (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/tests/automated/removeEventSource.js:75:6)
            at trigger (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/dist/fullcalendar.js:9275:25)
            at FC.View.Class.extend.trigger (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/dist/fullcalendar.js:7372:27)
        Expected 0 to be 2.
        Error: Expected 0 to be 2.
            at expectEventCnt (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/tests/automated/removeEventSource.js:109:57)
            at options.eventAfterAllRender (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/tests/automated/removeEventSource.js:75:6)
            at trigger (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/dist/fullcalendar.js:9275:25)
            at FC.View.Class.extend.trigger (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/dist/fullcalendar.js:7372:27)
Chrome 49.0.2623 (Windows 10 0.0.0) removeEventSource with a URL correctly removes events provided via `addEventSource` method FAILED
        Expected 0 to be 2.
        Error: Expected 0 to be 2.
            at expectEventCnt (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/tests/automated/removeEventSource.js:108:33)
            at options.eventAfterAllRender (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/tests/automated/removeEventSource.js:89:6)
            at trigger (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/dist/fullcalendar.js:9275:25)
            at FC.View.Class.extend.trigger (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/dist/fullcalendar.js:7372:27)
        Expected 0 to be 2.
        Error: Expected 0 to be 2.
            at expectEventCnt (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/tests/automated/removeEventSource.js:109:57)
            at options.eventAfterAllRender (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/tests/automated/removeEventSource.js:89:6)
            at trigger (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/dist/fullcalendar.js:9275:25)
            at FC.View.Class.extend.trigger (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/dist/fullcalendar.js:7372:27)
......
Chrome 49.0.2623 (Windows 10 0.0.0) removeEventSource with an object+url correctly removes events provided via `events` at initialization FAILED
        Expected 0 to be 2.
        Error: Expected 0 to be 2.
            at expectEventCnt (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/tests/automated/removeEventSource.js:108:33)
            at options.eventAfterAllRender (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/tests/automated/removeEventSource.js:61:6)
            at trigger (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/dist/fullcalendar.js:9275:25)
            at FC.View.Class.extend.trigger (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/dist/fullcalendar.js:7372:27)
        Expected 0 to be 2.
        Error: Expected 0 to be 2.
            at expectEventCnt (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/tests/automated/removeEventSource.js:109:57)
            at options.eventAfterAllRender (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/tests/automated/removeEventSource.js:61:6)
            at trigger (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/dist/fullcalendar.js:9275:25)
            at FC.View.Class.extend.trigger (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/dist/fullcalendar.js:7372:27)
Chrome 49.0.2623 (Windows 10 0.0.0) removeEventSource with an object+url correctly removes events provided via `eventSources` at initialization FAILED
        Expected 0 to be 2.
        Error: Expected 0 to be 2.
            at expectEventCnt (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/tests/automated/removeEventSource.js:108:33)
            at options.eventAfterAllRender (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/tests/automated/removeEventSource.js:75:6)
            at trigger (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/dist/fullcalendar.js:9275:25)
            at FC.View.Class.extend.trigger (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/dist/fullcalendar.js:7372:27)
        Expected 0 to be 2.
        Error: Expected 0 to be 2.
            at expectEventCnt (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/tests/automated/removeEventSource.js:109:57)
            at options.eventAfterAllRender (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/tests/automated/removeEventSource.js:75:6)
            at trigger (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/dist/fullcalendar.js:9275:25)
            at FC.View.Class.extend.trigger (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/dist/fullcalendar.js:7372:27)
Chrome 49.0.2623 (Windows 10 0.0.0) removeEventSource with an object+url correctly removes events provided via `addEventSource` method FAILED
        Expected 0 to be 2.
        Error: Expected 0 to be 2.
            at expectEventCnt (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/tests/automated/removeEventSource.js:108:33)
            at options.eventAfterAllRender (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/tests/automated/removeEventSource.js:89:6)
            at trigger (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/dist/fullcalendar.js:9275:25)
            at FC.View.Class.extend.trigger (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/dist/fullcalendar.js:7372:27)
        Expected 0 to be 2.
        Error: Expected 0 to be 2.
            at expectEventCnt (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/tests/automated/removeEventSource.js:109:57)
            at options.eventAfterAllRender (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/tests/automated/removeEventSource.js:89:6)
            at trigger (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/dist/fullcalendar.js:9275:25)
            at FC.View.Class.extend.trigger (C:/Users/Owner/Documents/GitHub/caseyjhol/fullcalendar/dist/fullcalendar.js:7372:27)
................................................................................
................................................................................
.............................................
Chrome 49.0.2623 (Windows 10 0.0.0): Executed 2017 of 2036 (7 FAILED) (skipped 1) (1 min 36.905 secs / 1 min 36.339 secs)

@caseyjhol
Copy link
Contributor Author

Can confirm that merging PR #3101 allows the tests to run without any errors.

@caseyjhol
Copy link
Contributor Author

Tests now passing successfully (both in master and this branch) after 2a600ea.

@knvpk
Copy link

knvpk commented May 11, 2016

Hi @caseyjhol , Thanks for this PR it is very helpful n my case, because i have many sources showing on single calendar, every time update,deleted i call refetch indirectly calling other sources also which is not required. With this PR so many requests are saved. Im actually waiting this to be released.

@caseyjhol
Copy link
Contributor Author

@espen @arshaw tests added

@knvpk
Copy link

knvpk commented May 18, 2016

When this will get merged?

@arshaw
Copy link
Member

arshaw commented Jun 5, 2016

@caseyjhol et al, sorry for the long delay. Thanks for the work on this. I know I gave prior approval of the API, but after spending more time understanding it and looking at the resulting code, I'm hoping we can simplify. Sorry to chime in so late 😞

From what it looks like, refetchEvents now accepts one or more filters that decide which event-sources get refetched. (for some reason I initially thought it filtered individual events, which doesn't make sense). So, if there is a { rendering: 'background' } filter, it will only match event-sources that have those properties on the top-level event source object and will disregard any rendering properties on individual events, no? If this is the case, I can imaging some resulting confusion.

Rather than provide utilities to filter which event sources get refetched, I'd rather put the filtering in the caller's control. So, they would get call getEventSources, filter the ones they want refetched, and then manually call refetchEventSource (a hypothetical new method) on each.

So, I'm proposing a single change to the API: the addition of a refetchEventSource method, which accepts a reference to an event source, or its primitive (like URL). What do you think? Again, sorry for any wasted work this opinion-change may have caused.

@arshaw arshaw added the WIP label Jun 5, 2016
@caseyjhol
Copy link
Contributor Author

caseyjhol commented Jun 6, 2016

That sounds good, and should be easy enough to implement. I do think we should also support passing through multiple sources as an array in one refetchEventSource call. It doesn't look like getEventSources is a method yet (#2433), so we'd have to add that too (as a separate pull request of course).

@caseyjhol caseyjhol changed the title add option to refetch subsets of events add option to refetch specific event sources Jun 6, 2016
@caseyjhol caseyjhol changed the title add option to refetch specific event sources add method to refetch specific event sources Jun 6, 2016
@arshaw
Copy link
Member

arshaw commented Jun 7, 2016

i definitely want to add getEventSources, it's well overdue

rangeStart = start;
rangeEnd = end;
_cache = sourceFilter ? cache : [];
cache = [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will clear all events from the cache, even in the event sources we want refetched. the result (i believe) will be that other event sources' events will be unintentionally cleared

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Event sources' events we want to keep (i.e. not refetch) are stored in _events in the source object. _events is built using _cache, which is only used in the case that we're using a filter. This line would probably make more sense as

if (sourceFilter) {
    _cache = cache;
}

@arshaw
Copy link
Member

arshaw commented Jun 7, 2016

i'd rather pass in only one event source to refetchEventSource to keep the API simpler.

HOWEVER, i understand there might be performance issues with multiple re-render. #2938 will solve this, but might be a while before it's implemented.

thus, i'm okay with providing a method to refetch multiple resources all at once. could we please call it refetchEventSources (plural) to make it more explicit?

@caseyjhol
Copy link
Contributor Author

It might not be a bad idea to pass through an inverse option too. This would be helpful for cases where somebody wanted to refetch all event sources except one or two. That's an option we could always add later, too, though.

@caseyjhol
Copy link
Contributor Author

I've got this working and ready to go (not pushed to GitHub yet), but it is dependent on getEventSources existing, of course. I made a comment in #2433 about the best way to proceed with that feature.

@caseyjhol
Copy link
Contributor Author

getEventSources added in #3214.

@caseyjhol caseyjhol changed the title add method to refetch specific event sources add refetchEventSources method to refetch specific event sources Jun 13, 2016
@arshaw
Copy link
Member

arshaw commented Jun 15, 2016

looks great 👍

@arshaw arshaw added Mergeable and removed WIP labels Jun 15, 2016
@caseyjhol
Copy link
Contributor Author

caseyjhol commented Jun 15, 2016

I want to add some tests for this, but this relies on getEventSources, obviously. Do you want me to do the tests using a mock getEventSources function (like the one below), and then update the tests later after FullCalendar officially supports getEventSources? Or do you just want me to hold off on the tests?

function getEventSources() {
    var eventSources = [];
    var events = $calendar.fullCalendar('clientEvents');

    for (var i = 0; i < events.length; i++) {
        var source = events[i].source;

        if (eventSources.indexOf(source) === -1) {
            eventSources.push(source);
        }
    }

    return eventSources;
}

@arshaw
Copy link
Member

arshaw commented Jun 16, 2016

could you actually just merge your other branch with getEventSources into this one, so you can use the real function? don't worry about muddying the diff, i can tell the difference.

@caseyjhol
Copy link
Contributor Author

getEventSources has been merged

@caseyjhol caseyjhol changed the title add refetchEventSources method to refetch specific event sources add getEventSources and refetchEventSources methods to refetch specific event sources Jun 16, 2016
@caseyjhol
Copy link
Contributor Author

Added tests for refetchEventSources.

@arshaw
Copy link
Member

arshaw commented Jun 17, 2016

good to go. thank you

@arshaw arshaw added this to the v2.8.0 milestone Jun 18, 2016
@arshaw
Copy link
Member

arshaw commented Jun 19, 2016

Code complete and docs written but not yet released. Will update this thread when released.

@caseyjhol i added some mods/tests to deal w/ race conditions a bit better

@arshaw arshaw closed this Jun 19, 2016
@arshaw
Copy link
Member

arshaw commented Jun 20, 2016

Released in v2.8.0.

http://fullcalendar.io/docs/event_data/getEventSources/

@arshaw
Copy link
Member

arshaw commented Jun 20, 2016

and http://fullcalendar.io/docs/event_data/refetchEventSources/

thank you for all your hard work @caseyjhol !

@caseyjhol caseyjhol deleted the refetchEvents-filter branch July 11, 2016 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

refetchEvents of a single source only refetchEvents for multiple specific sources
4 participants