@@ -66,12 +66,28 @@ export interface StateProps {
66
66
readonly stateName : string ;
67
67
68
68
/**
69
- * Specifies the events on enter. the conditions of the events are evaluated when the state is entered .
70
- * If the condition is `TRUE `, the actions of the event are performed .
69
+ * Specifies the events on enter. The conditions of the events will be evaluated when entering this state .
70
+ * If the condition of the event evaluates to `true `, the actions of the event will be executed .
71
71
*
72
- * @default - events on enter will not be set
72
+ * @default - no events will trigger on entering this state
73
73
*/
74
74
readonly onEnter ?: Event [ ] ;
75
+
76
+ /**
77
+ * Specifies the events on input. The conditions of the events will be evaluated when any input is received.
78
+ * If the condition of the event evaluates to `true`, the actions of the event will be executed.
79
+ *
80
+ * @default - no events will trigger on input in this state
81
+ */
82
+ readonly onInput ?: Event [ ] ;
83
+
84
+ /**
85
+ * Specifies the events on exit. The conditions of the events are evaluated when an exiting this state.
86
+ * If the condition evaluates to `true`, the actions of the event will be executed.
87
+ *
88
+ * @default - no events will trigger on exiting this state
89
+ */
90
+ readonly onExit ?: Event [ ] ;
75
91
}
76
92
77
93
/**
@@ -141,12 +157,18 @@ export class State {
141
157
}
142
158
143
159
private toStateJson ( scope : Construct , actionBindOptions : ActionBindOptions ) : CfnDetectorModel . StateProperty {
144
- const { onEnter } = this . props ;
160
+ const { onEnter, onInput , onExit } = this . props ;
145
161
return {
146
162
stateName : this . stateName ,
147
- onEnter : onEnter && { events : toEventsJson ( scope , actionBindOptions , onEnter ) } ,
148
- onInput : {
163
+ onEnter : onEnter && {
164
+ events : toEventsJson ( scope , actionBindOptions , onEnter ) ,
165
+ } ,
166
+ onInput : ( onInput || this . transitionEvents . length !== 0 ) ? {
167
+ events : toEventsJson ( scope , actionBindOptions , onInput ) ,
149
168
transitionEvents : toTransitionEventsJson ( scope , actionBindOptions , this . transitionEvents ) ,
169
+ } : undefined ,
170
+ onExit : onExit && {
171
+ events : toEventsJson ( scope , actionBindOptions , onExit ) ,
150
172
} ,
151
173
} ;
152
174
}
@@ -155,9 +177,9 @@ export class State {
155
177
function toEventsJson (
156
178
scope : Construct ,
157
179
actionBindOptions : ActionBindOptions ,
158
- events : Event [ ] ,
159
- ) : CfnDetectorModel . EventProperty [ ] {
160
- return events . map ( event => ( {
180
+ events ? : Event [ ] ,
181
+ ) : CfnDetectorModel . EventProperty [ ] | undefined {
182
+ return events ? .map ( event => ( {
161
183
eventName : event . eventName ,
162
184
condition : event . condition ?. evaluate ( ) ,
163
185
actions : event . actions ?. map ( action => action . bind ( scope , actionBindOptions ) . configuration ) ,
0 commit comments