How to configure stm to work with adding multiple events in the for loop. As below, I start a batch for each of the stores, multi add works as it should, because events are added at once. When I run undo, unfortunately only the last one is removed. Did I do something wrong with the configuration?
Multiadd:
if (date) {
let _date : Date = date;
eventStore.beginBatch();
assignmentStore.beginBatch();
resourceStore.beginBatch();
for(let i = 0; i < this.multiselectPayload.length; i++){
let event = new EventModel(this.multiselectPayload[i]);
event.setStartDate(_date, true);
let createdEvent = scheduler.eventStore.add(event);
let result : EventModel = scheduler.eventStore.find(x=>x.id === createdEvent[0].id) as
EventModel;
assignmentStore.assignEventToResource(event, context.resource);
await eventStore.project.commitAsync();
await assignmentStore.project.commitAsync();
await resourceStore.project.commitAsync();
_date = result.endDate as Date;
}
eventStore.endBatch();
assignmentStore.endBatch();
resourceStore.endBatch();
let differenceArray = this.sessionServiceEvents.filter(x =>
!this.multiselectPayload.includes(x));
this.sessionService.eventsToAddOnMultiselectArray.next([]);
this.sessionService.events.next(differenceArray);
}
State Tracking Manager Service:
export class StateTrackingService {
constructor(public sessionService: SessionService) {}
//private variables
undo: number;
redo: number;
public stmConfig = new StateTrackingManager({
autoRecord : true,
listeners : {
'recordingstop' : () => {
this.sessionService.sessionUndo.next((this.stmConfig.position - 1).toString());
this.sessionService.sessionRedo.next((this.stmConfig.queue.length - (this.stmConfig.position)).toString());
},
'restoringstop' : () => {
this.sessionService.sessionUndo.next((this.stmConfig.position - 1).toString());
this.sessionService.sessionRedo.next((this.stmConfig.queue.length - (this.stmConfig.position)).toString());
}
},
});
public setStateRecorder(resourceStore: SchedulerResourceStore, eventStore: SchedulerEventStore, assignmentStore: SchedulerAssignmentStore) {
//properties
this.stmConfig.autoRecord = this.stmConfig.autoRecord;
this.stmConfig.disabled = this.stmConfig.disabled;
//stores to record
this.stmConfig.addStore(resourceStore);
this.stmConfig.addStore(eventStore);
this.stmConfig.addStore(assignmentStore);
//enabling
this.stmConfig.enable();
}
}
Initialization of STM service in main component:
this.dragAndDropService.getDragFunction(this.scheduler, this.myDrag, this.assignmentStore, this.eventStore, this.resourceStore);