forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtransaction-manager.ts
More file actions
38 lines (33 loc) · 1.06 KB
/
transaction-manager.ts
File metadata and controls
38 lines (33 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { IPublicEnumTransitionType } from '@felce/lowcode-types';
import { runInAction } from 'mobx';
import EventEmitter from 'events';
class TransactionManager {
emitter = new EventEmitter();
executeTransaction = (
fn: () => void,
type: IPublicEnumTransitionType = IPublicEnumTransitionType.REPAINT,
): void => {
this.emitter.emit(`[${type}]startTransaction`);
runInAction(fn);
this.emitter.emit(`[${type}]endTransaction`);
};
onStartTransaction = (
fn: () => void,
type: IPublicEnumTransitionType = IPublicEnumTransitionType.REPAINT,
): (() => void) => {
this.emitter.on(`[${type}]startTransaction`, fn);
return () => {
this.emitter.off(`[${type}]startTransaction`, fn);
};
};
onEndTransaction = (
fn: () => void,
type: IPublicEnumTransitionType = IPublicEnumTransitionType.REPAINT,
): (() => void) => {
this.emitter.on(`[${type}]endTransaction`, fn);
return () => {
this.emitter.off(`[${type}]endTransaction`, fn);
};
};
}
export const transactionManager = new TransactionManager();