bug and workaround with createTimelineView & createUnitsView

In some cases we need to call createTimelineView() more than once. For example, several applications in one project, which are not related to each other, and they require timeline view.
But UI begins to run slower with a few calls createTimelineView (http://forum.dhtmlx.com/viewtopic.php?f=6&t=15951)
Due to the code

scheduler.attachEvent("onOptionsLoad", function() { O.order = {}; for (var P = 0; P < O.y_unit.length; P++) { O.order[O.y_unit[P].key] = P } if (O.name == scheduler._mode) { if (scheduler._date) { scheduler.setCurrentView(scheduler._date, scheduler._mode) } } });
Namely, setCurrentView calls the event “onViewChange” and each new challenge createTimelineView event onViewChange happening more and more number of times.
As an option, following workaround:

scheduler.attachEvent("onOptionsLoad", function() { O.order = {}; for (var P = 0; P < O.y_unit.length; P++) { O.order[O.y_unit[P].key] = P } if (O.name == scheduler._mode) { if (scheduler._date) { // scheduler.setCurrentView(scheduler._date, scheduler._mode) } } });
that is comment row scheduler.setCurrentView(scheduler._date, scheduler._mode)

and after that call

scheduler.callEvent("onOptionsLoad", []); scheduler.setCurrentView(scheduler.getState().date, scheduler.getState().mode);

instead of

scheduler.callEvent("onOptionsLoad", [])

where it is needed.
The same problem and workaround as about createUnitsView or joint use createTimelineView and createUnitsView.

Is there better workaround for this problem?

A bit better solution will be to replace

if (scheduler._date) { scheduler.setCurrentView(scheduler._date, scheduler._mode) }

with

if (scheduler._date && scheduler._mode == obj.name) { scheduler.setCurrentView(scheduler._date, scheduler._mode) }

In such case repaint command will be triggered only once, for the active mode
I think we will include such fix in the next version

Please ignore previous answer, it is useless :frowning:
Can you use createTimelineView with different “name” parameter each time?
If you are using the same name - code can’t separate old and new event handlers and as result many handlers ( not only the above one ) will be called two times.

Yes, I can generate unique “name” as for example timeline_day_{myFirstApp}, timeline_day_{mySecondApp} and so on.
In my case when I quit first app - first layout is destroyed (it’s not cached or hided in DOM. necessary measure against the slow work. We use ExtJs framework, and extjs-generate dom is enough huge). So if I want to open first app again, layout recreates. and now name must be
timeline_day_{myFirstApp}_{someUniqueId}. So I think it’s not very comfortable :slight_smile:

What about such solution :

dhtmlxscheduler_timeline.js

//this code will be executed only once
scheduler.fixTimeline = {
    _context : null,
    optionsLoadHandler : function() {
        var context = this._context;
        context.order = {};
        for (var P = context; P < context.y_unit.length; P++) {
            context.order[context.y_unit[P].key] = P
        }
        if (context.name == scheduler._mode) {
            if (scheduler._date) {
                scheduler.setCurrentView(scheduler._date, scheduler._mode)
            }
        }
    },
    setContext : function(context) {
        this._context = context;
    }
};

scheduler.attachEvent("onOptionsLoad", function() {
    scheduler.fixTimeline.optionsLoadHandler();
});

//function can be run as many times as needed
scheduler.createTimelineView = function(O) {
...
    scheduler.fixTimeline.setContext(O);
...
}

or something like that?