File tree Expand file tree Collapse file tree 4 files changed +16
-12
lines changed Expand file tree Collapse file tree 4 files changed +16
-12
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ class FsmSpec(
5
5
val initialState : String
6
6
) {
7
7
8
- fun add (transitionRecipe : TransitionSpec .() -> TransitionSpec ): FsmSpec {
8
+ fun add (transitionRecipe : TransitionSpec .() -> Unit ): FsmSpec {
9
9
transitions.add(Transition .create(transitionRecipe))
10
10
return this
11
11
}
Original file line number Diff line number Diff line change @@ -3,9 +3,8 @@ package dsl
3
3
data class Transition (val event : Event , val stateFlow : StateFlow ) {
4
4
5
5
companion object {
6
- fun create (transitionSpec : TransitionSpec .() -> TransitionSpec ): Transition {
7
- return TransitionSpec ()
8
- .transitionSpec()
6
+ fun create (transitionSpec : TransitionSpec .() -> Unit ): Transition {
7
+ return TransitionSpec ().apply (transitionSpec)
9
8
.build()
10
9
}
11
10
}
Original file line number Diff line number Diff line change @@ -6,19 +6,16 @@ class TransitionSpec(
6
6
private var stateTo : String = " "
7
7
) {
8
8
9
- fun on (event : String ): TransitionSpec {
9
+ fun on (event : String ) {
10
10
this .event = event
11
- return this
12
11
}
13
12
14
- fun from (state : String ): TransitionSpec {
13
+ fun from (state : String ) {
15
14
stateFrom = state
16
- return this
17
15
}
18
16
19
- fun into (state : String ): TransitionSpec {
17
+ fun into (state : String ) {
20
18
stateTo = state
21
- return this
22
19
}
23
20
24
21
fun build (): Transition {
Original file line number Diff line number Diff line change @@ -9,8 +9,16 @@ class FsmTest {
9
9
fun a () {
10
10
// when:
11
11
val fsm = Fsm .create(initialState = " locked" ) {
12
- add { on(" coin" ).from(" locked" ).into(" unlocked" ) }
13
- add { on(" pass" ).from(" unlocked" ).into(" locked" ) }
12
+ add {
13
+ on(" coin" )
14
+ from(" locked" )
15
+ into(" unlocked" )
16
+ }
17
+ add {
18
+ on(" pass" )
19
+ from(" unlocked" )
20
+ into(" locked" )
21
+ }
14
22
}
15
23
16
24
// then:
You can’t perform that action at this time.
0 commit comments