Our pure JavaScript Scheduler component


Post by david-molnar-oculai »

I want to add "refresh" handler on the resource store. I add a listener. In the event "this" refers to the ResourceStore. "source" is also the ResourceStore. How can I get access to the SchedulerPro instance?


Post by ghulam.ghous »

You can't get access to the schedulerPro instance on this. The reason for this as store can be used by more then one schedulers. So if you want to access the schedulerPro instance, you will have to use the SchedulerPro ref.


Post by david-molnar-oculai »

What about the ProjectModel? Can you get access to the scheduler instance from there?

Why not let then get access to all scheduler instances from the Stores? It's just an unncessary complication, that the instance has to come from "outside" using the ref.


Post by marcio »

Hey David,

The ProjectModel does not directly provide access to the SchedulerPro instance either. The design is such that stores can be shared across multiple components, hence they do not maintain a direct reference to any specific SchedulerPro instance.

To access the SchedulerPro instance, using the ref is the recommended approach. This ensures you are interacting with the correct instance, especially in applications where multiple schedulers might be using the same data stores.

Best regards,
Márcio

How to ask for help? Please read our Support Policy


Post by david-molnar-oculai »

It's the typical case of trying to have a too "nice" design. I agree that it sounds good that the instances are not available. on the stores, as they can be associated with multiple. However, I assume 99% of the people use only one instance. For them it'd be easier if the instance would be "just there". For every other event handler the instance can be easily accessed, for event handlers on the stores one needs "special" logic.


Post by arcady »

Hello,

Data level has no notion of UI.
And even out of the box there are multiple instances of resource/task/dependency/assignments stores.
UI makes clones and chains of the original stores.

If you need the Scheduler to react on certain custom data level occasion you should trigger events:

class MyResourceStore extends ResourceStore {

    someMethod() {
        this.trigger('myCustomEvent', { foo : 'Bar' });
    }

}

const scheduler = new SchedulerPro({
    project : {
        listeners : {
            resourceStore : {
                myCustomEvent : () => {
                    scheduler.refreshRows();
                }
            }
        }
    },
    ...
});

// or

scheduler.on({
    myCustomEvent : () => {
        scheduler.refreshRows();
    }
});

Best regards,
Arcady


Post by david-molnar-oculai »

I managed to rewrite our code to use only the ProjectModel, rather than the full scheduler. This removes the need to get the instance.


Post Reply