@@ -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
@@ -226,7 +237,7 @@ public class StateMachine<S: StateType, E: StateEventType>
226237 let order = handlerInfo. order
227238 let handler = handlerInfo. handler
228239
229- handler ( context : HandlerContext ( event: event, transition: transition, order: order, userInfo: userInfo) )
240+ handler ( HandlerContext ( event: event, transition: transition, order: order, userInfo: userInfo) )
230241 }
231242
232243 didTransit = true
@@ -236,7 +247,7 @@ public class StateMachine<S: StateType, E: StateEventType>
236247 let order = handlerInfo. order
237248 let handler = handlerInfo. handler
238249
239- handler ( context : HandlerContext ( event: event, transition: transition, order: order, userInfo: userInfo) )
250+ handler ( HandlerContext ( event: event, transition: transition, order: order, userInfo: userInfo) )
240251 }
241252 }
242253
@@ -338,7 +349,7 @@ public class StateMachine<S: StateType, E: StateEventType>
338349 return self . addRoute ( route)
339350 }
340351
341- public func addRoute( transition: Transition , condition : @autoclosure ( ) -> Bool ) -> RouteID
352+ public func addRoute( transition: Transition , @autoclosure ( escaping ) condition : ( ) -> Bool ) -> RouteID
342353 {
343354 return self . addRoute ( transition, condition: { t in condition ( ) } )
344355 }
@@ -388,7 +399,7 @@ public class StateMachine<S: StateType, E: StateEventType>
388399 return self . addRoute ( route, handler: handler)
389400 }
390401
391- public func addRoute( transition: Transition , condition : @autoclosure ( ) -> Bool , handler: Handler ) -> ( RouteID , HandlerID )
402+ public func addRoute( transition: Transition , @autoclosure ( escaping ) condition : ( ) -> Bool , handler: Handler ) -> ( RouteID , HandlerID )
392403 {
393404 return self . addRoute ( transition, condition: { t in condition ( ) } , handler: handler)
394405 }
@@ -403,7 +414,7 @@ public class StateMachine<S: StateType, E: StateEventType>
403414 let handlerID = self . addHandler ( transition) { [ weak self] context in
404415 if let self_ = self {
405416 if self_. _canPassCondition ( condition, transition: context. transition) {
406- handler ( context: context )
417+ handler ( context)
407418 }
408419 }
409420 }
@@ -620,7 +631,7 @@ public class StateMachine<S: StateType, E: StateEventType>
620631 return self . addRouteChain ( routeChain, handler: handler)
621632 }
622633
623- public func addRouteChain( chain: TransitionChain , condition : @autoclosure ( ) -> Bool , handler: Handler ) -> ( RouteID , HandlerID )
634+ public func addRouteChain( chain: TransitionChain , @autoclosure ( escaping ) condition : ( ) -> Bool , handler: Handler ) -> ( RouteID , HandlerID )
624635 {
625636 return self . addRouteChain ( chain, condition: { t in condition ( ) } , handler: handler)
626637 }
@@ -743,7 +754,7 @@ public class StateMachine<S: StateType, E: StateEventType>
743754 if chainingCount < allCount {
744755 shouldStop = true
745756 if isError {
746- handler ( context: context )
757+ handler ( context)
747758 }
748759 }
749760 }
@@ -758,7 +769,7 @@ public class StateMachine<S: StateType, E: StateEventType>
758769 shouldStop = true
759770
760771 if !isError {
761- handler ( context: context )
772+ handler ( context)
762773 }
763774 }
764775 }
@@ -786,7 +797,7 @@ public class StateMachine<S: StateType, E: StateEventType>
786797 return self . addRouteEvent ( event, routes: routes)
787798 }
788799
789- public func addRouteEvent( event: Event , transitions: [ Transition ] , condition : @autoclosure ( ) -> Bool ) -> [ RouteID ]
800+ public func addRouteEvent( event: Event , transitions: [ Transition ] , @autoclosure ( escaping ) condition : ( ) -> Bool ) -> [ RouteID ]
790801 {
791802 return self . addRouteEvent ( event, transitions: transitions, condition: { t in condition ( ) } )
792803 }
@@ -818,7 +829,7 @@ public class StateMachine<S: StateType, E: StateEventType>
818829 return ( routeIDs, handlerID)
819830 }
820831
821- public func addRouteEvent( event: Event , transitions: [ Transition ] , condition : @autoclosure ( ) -> Bool , handler: Handler ) -> ( [ RouteID ] , HandlerID )
832+ public func addRouteEvent( event: Event , transitions: [ Transition ] , @autoclosure ( escaping ) condition : ( ) -> Bool , handler: Handler ) -> ( [ RouteID ] , HandlerID )
822833 {
823834 return self . addRouteEvent ( event, transitions: transitions, condition: { t in condition ( ) } , handler: handler)
824835 }
@@ -845,7 +856,7 @@ public class StateMachine<S: StateType, E: StateEventType>
845856
846857 let handlerID = self . addHandler ( nil => nil , order: order) { [ weak self] context in
847858 if context. event == event {
848- handler ( context: context )
859+ handler ( context)
849860 }
850861 }
851862
0 commit comments