@@ -26,14 +26,14 @@ public class StateMachineRouteID<S: StateType, E: StateEventType>
2626 self . transition = transition
2727 self . routeKey = routeKey
2828 self . event = event
29-
29+
3030 self . bundledRouteIDs = nil
3131 }
3232
3333 private init ( bundledRouteIDs: [ StateMachineRouteID < S , E > ] ? )
3434 {
3535 self . bundledRouteIDs = bundledRouteIDs
36-
36+
3737 self . transition = nil
3838 self . routeKey = nil
3939 self . event = nil
@@ -54,14 +54,14 @@ public class StateMachineHandlerID<S: StateType, E: StateEventType>
5454 {
5555 self . transition = transition
5656 self . handlerKey = handlerKey
57-
57+
5858 self . bundledHandlerIDs = nil
5959 }
6060
6161 private init ( bundledHandlerIDs: [ StateMachineHandlerID < S , E > ] ? )
6262 {
6363 self . bundledHandlerIDs = bundledHandlerIDs
64-
64+
6565 self . transition = nil
6666 self . handlerKey = nil
6767 }
@@ -88,7 +88,7 @@ internal class _StateMachineHandlerInfo<S: StateType, E: StateEventType>
8888public class StateMachine < S: StateType , E: StateEventType >
8989{
9090 public typealias HandlerOrder = UInt8
91- public typealias Handler = ( ( context : HandlerContext ) -> Void )
91+ public typealias Handler = ( HandlerContext -> Void )
9292 public typealias HandlerContext = ( event: Event , transition: Transition , order: HandlerOrder , userInfo: Any ? )
9393
9494 internal typealias State = S
@@ -238,7 +238,7 @@ public class StateMachine<S: StateType, E: StateEventType>
238238 let order = handlerInfo. order
239239 let handler = handlerInfo. handler
240240
241- handler ( context : HandlerContext ( event: event, transition: transition, order: order, userInfo: userInfo) )
241+ handler ( HandlerContext ( event: event, transition: transition, order: order, userInfo: userInfo) )
242242 }
243243
244244 didTransit = true
@@ -248,7 +248,7 @@ public class StateMachine<S: StateType, E: StateEventType>
248248 let order = handlerInfo. order
249249 let handler = handlerInfo. handler
250250
251- handler ( context : HandlerContext ( event: event, transition: transition, order: order, userInfo: userInfo) )
251+ handler ( HandlerContext ( event: event, transition: transition, order: order, userInfo: userInfo) )
252252 }
253253 }
254254
@@ -350,6 +350,11 @@ public class StateMachine<S: StateType, E: StateEventType>
350350 return self . addRoute ( route)
351351 }
352352
353+ public func addRoute( transition: Transition , @autoclosure ( escaping) condition: ( ) -> Bool ) -> RouteID
354+ {
355+ return self . addRoute ( transition, condition: { t in condition ( ) } )
356+ }
357+
353358 public func addRoute( route: Route ) -> RouteID
354359 {
355360 return self . _addRoute ( route)
@@ -395,6 +400,11 @@ public class StateMachine<S: StateType, E: StateEventType>
395400 return self . addRoute ( route, handler: handler)
396401 }
397402
403+ public func addRoute( transition: Transition , @autoclosure ( escaping) condition: ( ) -> Bool , handler: Handler ) -> ( RouteID , HandlerID )
404+ {
405+ return self . addRoute ( transition, condition: { t in condition ( ) } , handler: handler)
406+ }
407+
398408 public func addRoute( route: Route , handler: Handler ) -> ( RouteID , HandlerID )
399409 {
400410 let transition = route. transition
@@ -405,7 +415,7 @@ public class StateMachine<S: StateType, E: StateEventType>
405415 let handlerID = self . addHandler ( transition) { [ weak self] context in
406416 if let self_ = self {
407417 if self_. _canPassCondition ( condition, transition: context. transition) {
408- handler ( context: context )
418+ handler ( context)
409419 }
410420 }
411421 }
@@ -622,6 +632,11 @@ public class StateMachine<S: StateType, E: StateEventType>
622632 return self . addRouteChain ( routeChain, handler: handler)
623633 }
624634
635+ public func addRouteChain( chain: TransitionChain , @autoclosure ( escaping) condition: ( ) -> Bool , handler: Handler ) -> ( RouteID , HandlerID )
636+ {
637+ return self . addRouteChain ( chain, condition: { t in condition ( ) } , handler: handler)
638+ }
639+
625640 public func addRouteChain( chain: RouteChain , handler: Handler ) -> ( RouteID , HandlerID )
626641 {
627642 var routeIDs : [ RouteID ] = [ ]
@@ -740,7 +755,7 @@ public class StateMachine<S: StateType, E: StateEventType>
740755 if chainingCount < allCount {
741756 shouldStop = true
742757 if isError {
743- handler ( context: context )
758+ handler ( context)
744759 }
745760 }
746761 }
@@ -755,7 +770,7 @@ public class StateMachine<S: StateType, E: StateEventType>
755770 shouldStop = true
756771
757772 if !isError {
758- handler ( context: context )
773+ handler ( context)
759774 }
760775 }
761776 }
@@ -783,6 +798,11 @@ public class StateMachine<S: StateType, E: StateEventType>
783798 return self . addRouteEvent ( event, routes: routes)
784799 }
785800
801+ public func addRouteEvent( event: Event , transitions: [ Transition ] , @autoclosure ( escaping) condition: ( ) -> Bool ) -> [ RouteID ]
802+ {
803+ return self . addRouteEvent ( event, transitions: transitions, condition: { t in condition ( ) } )
804+ }
805+
786806 public func addRouteEvent( event: Event , routes: [ Route ] ) -> [ RouteID ]
787807 {
788808 var routeIDs : [ RouteID ] = [ ]
@@ -809,6 +829,11 @@ public class StateMachine<S: StateType, E: StateEventType>
809829
810830 return ( routeIDs, handlerID)
811831 }
832+
833+ public func addRouteEvent( event: Event , transitions: [ Transition ] , @autoclosure ( escaping) condition: ( ) -> Bool , handler: Handler ) -> ( [ RouteID ] , HandlerID )
834+ {
835+ return self . addRouteEvent ( event, transitions: transitions, condition: { t in condition ( ) } , handler: handler)
836+ }
812837
813838 public func addRouteEvent( event: Event , routes: [ Route ] , handler: Handler ) -> ( [ RouteID ] , HandlerID )
814839 {
@@ -832,7 +857,7 @@ public class StateMachine<S: StateType, E: StateEventType>
832857
833858 let handlerID = self . addHandler ( nil => nil , order: order) { [ weak self] context in
834859 if context. event == event {
835- handler ( context: context )
860+ handler ( context)
836861 }
837862 }
838863
0 commit comments