Our pure JavaScript Scheduler component


Post by pmiklashevich »

Hello,

Regarding the second issue, when you update a field which takes a part in scheduling, for example "duration" or "resourceId", the Engine recalculates the events. It does it asynchronously. So when you call suspendEvents, set new data, the async rescheduling begins. Then you synchronously call resumeEvents and when the Engine calculation is done and data is ready, store events are not suspended, and the update event is fired. This logic is described in details in our guides: https://www.bryntum.com/docs/scheduler-pro/#guides/schedulerpro/project_data.md#data-consistency

The possible solution is to call await project.commitAsync() wfter data is changed. This will start rescheduling manually. So you resume store events after the calculation is done.

You can check the following code in the schedulerpro/examples/drag-from-grid/ demo.
1.Run in console to add listeners and setup functions:

schedulerPro.eventStore.on({
    update() {
        console.log('Event updated');
    }
});

schedulerPro.assignmentStore.on({
    update() {
        console.log('Assignment updated');
    }
});

updateAssignmentAsync = async () => {
    schedulerPro.assignmentStore.suspendEvents();
    const assignment = schedulerPro.assignmentStore.getById(8);
    assignment.resourceId = 12;
    await schedulerPro.project.commitAsync();
    schedulerPro.assignmentStore.resumeEvents();
};

updateEventAsync = async () => {
    schedulerPro.eventStore.suspendEvents();
    const event = schedulerPro.eventStore.getById(8);
    event.duration = 2;
    await schedulerPro.project.commitAsync();
    schedulerPro.eventStore.resumeEvents();
};

updateAssignment = () => {
    schedulerPro.assignmentStore.suspendEvents();
    const assignment = schedulerPro.assignmentStore.getById(8);
    assignment.resourceId = 12;
    schedulerPro.assignmentStore.resumeEvents();
};

updateEvent = () => {
    schedulerPro.eventStore.suspendEvents();
    const event = schedulerPro.eventStore.getById(8);
    event.duration = 2;
    schedulerPro.eventStore.resumeEvents();
};

2.Now try to call updateAssignment and updateEvent. You can see update handlers are called and the view is updated.
3.Reload the page, repeat step #1, and now call updateAssignmentAsync and updateEventAsync. You can see that handlers are not called. And nothing has changed in the view. Call schedulerPro.refreshRows() to update the view.

Hope this will help you to solve the issue!

Best regards,
Pavel

Pavlo Miklashevych
Sr. Frontend Developer


Post by imkookoo »

Ahhhh, great! That does solve the issue. I'm just learning to using/understanding the whole Promise / async / await paradigm. After changing the function to be async, and calling resumeEvents after an await on the commitAsync, everything looks good now. Thank you for the advice!


Post Reply