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

inst.refresh() causing `Maximum call stack size exceeded` #369

Closed
romant opened this Issue Dec 20, 2015 · 2 comments

Comments

Projects
None yet
2 participants
@romant
Copy link

romant commented Dec 20, 2015

using onMonthLoaded, and setting it to an array

onMonthLoaded: function (year, month, inst)
        {
        inst.settings.marked = events;
        inst.refresh();
        }

This is practically out of the examples provided; only am generating the array prior. In this case it's set to:

    var events = [  
            { d: '12/31', color: 'rgb(255,0,0)' }, 
            { d: '12/24', color: 'rgb(255,0,0)'}, 
            { d: '12/25', color: 'rgb(255,0,0)'},
            { d: new Date(), color: 'rgb(255,0,0)'},
            { d: new Date(), color: 'rgb(255,0,0)'},
        ];

The inst.refresh() presence causes a Maximum call stack size exceeded error to be thrown.

If after the function call, I instead use $("#calendar").mobiscroll('refresh') - it goe through without a hitch.

Why the difference in behaviour?

Many thanks.

PS:

no libraries are loaded beyond mobiscroll. Literally an empty, vanilla playground.

@dioslaska

This comment has been minimized.

Copy link
Contributor

dioslaska commented Dec 21, 2015

Since v2.17.0 the refresh method will also trigger the onMonthLoaded event (#336).
So, calling refresh method inside the onMonthLoaded event will result in an infinite loop.
As a workaround you can use a flag to prevent this:

onMonthLoaded: function (year, month, inst) {
    if (!inst.refreshing) {
        inst.settings.marked = events;
        inst.refreshing = true;
        inst.refresh();
        inst.refreshing = false;
    }
} 
@dioslaska

This comment has been minimized.

Copy link
Contributor

dioslaska commented Apr 20, 2016

Fixed in v2.17.2

Use the onMonthLoading event in combination with the redraw method.

The main differences:

  • the onMonthLoading event is triggered before the markup is generated, so if marked days or events are not added async, refresh or redraw is not needed
  • the redraw method also regenerates the month markup, but data won't be reloaded and the onMonthLoading event will not be triggered

Sync:

onMonthLoading: function (year, month, inst) {
    inst.settings.marked = events;
}

Async:

onMonthLoading: function (year, month, inst) {
    $.ajax({
        url: 'http://www.example.com/getMarkedDays?year=' + year + '&month=' + month,
        dataType: 'json',
        success : function (data) {

            inst.settings.marked = [];

            for (var i = 0; i < data.length; i++) {
                inst.settings.marked.push({
                    d: new Date(data[i].date), // Make sure that a javascript date object is passed
                    text: data[i].text
                });
            }

            // Redraw the view to display new data
            inst.redraw();
        }
    });
}

@dioslaska dioslaska closed this Apr 20, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment