1
1
import { Sequence , Step } from './definition' ;
2
2
import { CustomAction , DefinitionChangeType , DesignerConfiguration } from './designer-configuration' ;
3
3
import { DesignerState } from './designer-state' ;
4
+ import { StateModifier } from './modifier/state-modifier' ;
4
5
5
6
export class CustomActionController {
6
- public constructor ( private readonly configuration : DesignerConfiguration , private readonly state : DesignerState ) { }
7
+ public constructor (
8
+ private readonly configuration : DesignerConfiguration ,
9
+ private readonly state : DesignerState ,
10
+ private readonly stateModifier : StateModifier
11
+ ) { }
7
12
8
13
public trigger ( action : CustomAction , step : Step | null , sequence : Sequence ) {
9
14
const handler = this . configuration . customActionHandler ;
@@ -12,20 +17,28 @@ export class CustomActionController {
12
17
return ;
13
18
}
14
19
15
- const context = {
16
- notifyStepNameChanged : ( stepId : string ) => this . notifyStepChanged ( DefinitionChangeType . stepNameChanged , stepId ) ,
17
- notifyStepPropertiesChanged : ( stepId : string ) => this . notifyStepChanged ( DefinitionChangeType . stepPropertyChanged , stepId ) ,
18
- notifyStepInserted : ( stepId : string ) => this . notifyStepChanged ( DefinitionChangeType . stepInserted , stepId ) ,
19
- notifyStepMoved : ( stepId : string ) => this . notifyStepChanged ( DefinitionChangeType . stepMoved , stepId ) ,
20
- notifyStepDeleted : ( stepId : string ) => this . notifyStepChanged ( DefinitionChangeType . stepDeleted , stepId )
21
- } ;
20
+ const context = this . createCustomActionHandlerContext ( ) ;
22
21
handler ( action , step , sequence , context ) ;
23
22
}
24
23
25
- private notifyStepChanged ( changeType : DefinitionChangeType , stepId : string ) {
24
+ private createCustomActionHandlerContext ( ) {
25
+ return {
26
+ notifyStepNameChanged : ( stepId : string ) => this . notifyStepChanged ( DefinitionChangeType . stepNameChanged , stepId , false ) ,
27
+ notifyStepPropertiesChanged : ( stepId : string ) =>
28
+ this . notifyStepChanged ( DefinitionChangeType . stepPropertyChanged , stepId , false ) ,
29
+ notifyStepInserted : ( stepId : string ) => this . notifyStepChanged ( DefinitionChangeType . stepInserted , stepId , true ) ,
30
+ notifyStepMoved : ( stepId : string ) => this . notifyStepChanged ( DefinitionChangeType . stepMoved , stepId , true ) ,
31
+ notifyStepDeleted : ( stepId : string ) => this . notifyStepChanged ( DefinitionChangeType . stepDeleted , stepId , true )
32
+ } ;
33
+ }
34
+
35
+ private notifyStepChanged ( changeType : DefinitionChangeType , stepId : string , updateDependencies : boolean ) {
26
36
if ( ! stepId ) {
27
37
throw new Error ( 'Step id is empty' ) ;
28
38
}
29
39
this . state . notifyDefinitionChanged ( changeType , stepId ) ;
40
+ if ( updateDependencies ) {
41
+ this . stateModifier . updateDependencies ( ) ;
42
+ }
30
43
}
31
44
}
0 commit comments