You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
841 B
30 lines
841 B
|
4 months ago
|
import { GraphEvent } from '../constants';
|
||
|
|
import { GraphLifeCycleEvent } from '../utils/event';
|
||
|
|
export class BatchController {
|
||
|
|
constructor(context) {
|
||
|
|
this.batchCount = 0;
|
||
|
|
this.context = context;
|
||
|
|
}
|
||
|
|
emit(event) {
|
||
|
|
const { graph } = this.context;
|
||
|
|
graph.emit(event.type, event);
|
||
|
|
}
|
||
|
|
startBatch(initiate = true) {
|
||
|
|
this.batchCount++;
|
||
|
|
if (this.batchCount === 1)
|
||
|
|
this.emit(new GraphLifeCycleEvent(GraphEvent.BATCH_START, { initiate }));
|
||
|
|
}
|
||
|
|
endBatch() {
|
||
|
|
this.batchCount--;
|
||
|
|
if (this.batchCount === 0)
|
||
|
|
this.emit(new GraphLifeCycleEvent(GraphEvent.BATCH_END));
|
||
|
|
}
|
||
|
|
get isBatching() {
|
||
|
|
return this.batchCount > 0;
|
||
|
|
}
|
||
|
|
destroy() {
|
||
|
|
// @ts-ignore
|
||
|
|
this.context = null;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
//# sourceMappingURL=batch.js.map
|