@@ -26,11 +26,17 @@ public class StateMachineRouteID<S: StateType, E: StateEventType>
2626 self . transition = transition
2727 self . routeKey = routeKey
2828 self . event = event
29+
30+ self . bundledRouteIDs = nil
2931 }
3032
3133 private init ( bundledRouteIDs: [ StateMachineRouteID < S , E > ] ? )
3234 {
3335 self . bundledRouteIDs = bundledRouteIDs
36+
37+ self . transition = nil
38+ self . routeKey = nil
39+ self . event = nil
3440 }
3541}
3642
@@ -48,11 +54,16 @@ public class StateMachineHandlerID<S: StateType, E: StateEventType>
4854 {
4955 self . transition = transition
5056 self . handlerKey = handlerKey
57+
58+ self . bundledHandlerIDs = nil
5159 }
5260
5361 private init ( bundledHandlerIDs: [ StateMachineHandlerID < S , E > ] ? )
5462 {
5563 self . bundledHandlerIDs = bundledHandlerIDs
64+
65+ self . transition = nil
66+ self . handlerKey = nil
5667 }
5768}
5869
@@ -77,7 +88,7 @@ internal class _StateMachineHandlerInfo<S: StateType, E: StateEventType>
7788public class StateMachine < S: StateType , E: StateEventType >
7889{
7990 public typealias HandlerOrder = UInt8
80- public typealias Handler = ( ( context : HandlerContext ) -> Void )
91+ public typealias Handler = ( HandlerContext -> Void )
8192 public typealias HandlerContext = ( event: Event , transition: Transition , order: HandlerOrder , userInfo: Any ? )
8293
8394 internal typealias State = S
@@ -227,7 +238,7 @@ public class StateMachine<S: StateType, E: StateEventType>
227238 let order = handlerInfo. order
228239 let handler = handlerInfo. handler
229240
230- handler ( context : HandlerContext ( event: event, transition: transition, order: order, userInfo: userInfo) )
241+ handler ( HandlerContext ( event: event, transition: transition, order: order, userInfo: userInfo) )
231242 }
232243
233244 didTransit = true
@@ -237,7 +248,7 @@ public class StateMachine<S: StateType, E: StateEventType>
237248 let order = handlerInfo. order
238249 let handler = handlerInfo. handler
239250
240- handler ( context : HandlerContext ( event: event, transition: transition, order: order, userInfo: userInfo) )
251+ handler ( HandlerContext ( event: event, transition: transition, order: order, userInfo: userInfo) )
241252 }
242253 }
243254
@@ -339,7 +350,7 @@ public class StateMachine<S: StateType, E: StateEventType>
339350 return self . addRoute ( route)
340351 }
341352
342- public func addRoute( transition: Transition , condition : @autoclosure ( ) -> Bool ) -> RouteID
353+ public func addRoute( transition: Transition , @autoclosure ( escaping ) condition : ( ) -> Bool ) -> RouteID
343354 {
344355 return self . addRoute ( transition, condition: { t in condition ( ) } )
345356 }
@@ -389,7 +400,7 @@ public class StateMachine<S: StateType, E: StateEventType>
389400 return self . addRoute ( route, handler: handler)
390401 }
391402
392- public func addRoute( transition: Transition , condition : @autoclosure ( ) -> Bool , handler: Handler ) -> ( RouteID , HandlerID )
403+ public func addRoute( transition: Transition , @autoclosure ( escaping ) condition : ( ) -> Bool , handler: Handler ) -> ( RouteID , HandlerID )
393404 {
394405 return self . addRoute ( transition, condition: { t in condition ( ) } , handler: handler)
395406 }
@@ -404,7 +415,7 @@ public class StateMachine<S: StateType, E: StateEventType>
404415 let handlerID = self . addHandler ( transition) { [ weak self] context in
405416 if let self_ = self {
406417 if self_. _canPassCondition ( condition, transition: context. transition) {
407- handler ( context: context )
418+ handler ( context)
408419 }
409420 }
410421 }
@@ -621,7 +632,7 @@ public class StateMachine<S: StateType, E: StateEventType>
621632 return self . addRouteChain ( routeChain, handler: handler)
622633 }
623634
624- public func addRouteChain( chain: TransitionChain , condition : @autoclosure ( ) -> Bool , handler: Handler ) -> ( RouteID , HandlerID )
635+ public func addRouteChain( chain: TransitionChain , @autoclosure ( escaping ) condition : ( ) -> Bool , handler: Handler ) -> ( RouteID , HandlerID )
625636 {
626637 return self . addRouteChain ( chain, condition: { t in condition ( ) } , handler: handler)
627638 }
@@ -744,7 +755,7 @@ public class StateMachine<S: StateType, E: StateEventType>
744755 if chainingCount < allCount {
745756 shouldStop = true
746757 if isError {
747- handler ( context: context )
758+ handler ( context)
748759 }
749760 }
750761 }
@@ -759,7 +770,7 @@ public class StateMachine<S: StateType, E: StateEventType>
759770 shouldStop = true
760771
761772 if !isError {
762- handler ( context: context )
773+ handler ( context)
763774 }
764775 }
765776 }
@@ -787,7 +798,7 @@ public class StateMachine<S: StateType, E: StateEventType>
787798 return self . addRouteEvent ( event, routes: routes)
788799 }
789800
790- public func addRouteEvent( event: Event , transitions: [ Transition ] , condition : @autoclosure ( ) -> Bool ) -> [ RouteID ]
801+ public func addRouteEvent( event: Event , transitions: [ Transition ] , @autoclosure ( escaping ) condition : ( ) -> Bool ) -> [ RouteID ]
791802 {
792803 return self . addRouteEvent ( event, transitions: transitions, condition: { t in condition ( ) } )
793804 }
@@ -819,7 +830,7 @@ public class StateMachine<S: StateType, E: StateEventType>
819830 return ( routeIDs, handlerID)
820831 }
821832
822- public func addRouteEvent( event: Event , transitions: [ Transition ] , condition : @autoclosure ( ) -> Bool , handler: Handler ) -> ( [ RouteID ] , HandlerID )
833+ public func addRouteEvent( event: Event , transitions: [ Transition ] , @autoclosure ( escaping ) condition : ( ) -> Bool , handler: Handler ) -> ( [ RouteID ] , HandlerID )
823834 {
824835 return self . addRouteEvent ( event, transitions: transitions, condition: { t in condition ( ) } , handler: handler)
825836 }
@@ -846,7 +857,7 @@ public class StateMachine<S: StateType, E: StateEventType>
846857
847858 let handlerID = self . addHandler ( nil => nil , order: order) { [ weak self] context in
848859 if context. event == event {
849- handler ( context: context )
860+ handler ( context)
850861 }
851862 }
852863
0 commit comments