Skip to content

Commit 15e4120

Browse files
committed
Merge pull request #22 from ReactKit/swift/1.2
Swift 1.2 Support
2 parents 62e5e1a + 52cd640 commit 15e4120

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

SwiftState/HierarchicalStateMachine.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class HierarchicalStateMachine<S: StateType, E: StateEventType>: StateMac
6161
{
6262
assert(state is HSM.State, "HSM state must be String.")
6363

64-
let components = split(state as HSM.State, { $0 == "." }, maxSplit: 1)
64+
let components = split(state as! HSM.State, maxSplit: 1) { $0 == "." }
6565

6666
switch components.count {
6767
case 2:
@@ -85,7 +85,7 @@ public class HierarchicalStateMachine<S: StateType, E: StateEventType>: StateMac
8585
let (submachine, substate) = self._submachineTupleForState(self._state)
8686

8787
if let submachine = submachine {
88-
self._state = "\(submachine.name).\(submachine.state)" as State
88+
self._state = "\(submachine.name).\(submachine.state)" as! State
8989
}
9090

9191
return self._state
@@ -147,7 +147,7 @@ public class HierarchicalStateMachine<S: StateType, E: StateEventType>: StateMac
147147
// try changing submachine-internal state
148148
if fromSubmachine != nil && toSubmachine != nil && fromSubmachine === toSubmachine {
149149

150-
if toSubmachine!.canTryState(toSubstate, forEvent: event as HSM.Event) {
150+
if toSubmachine!.canTryState(toSubstate, forEvent: event as! HSM.Event) {
151151

152152
//
153153
// NOTE:

SwiftState/StateMachine.swift

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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>
7788
public 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

SwiftState/StateRoute.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public struct StateRoute<S: StateType>
2222
self.condition = condition
2323
}
2424

25-
public init(transition: Transition, condition: @autoclosure () -> Bool)
25+
public init(transition: Transition, @autoclosure(escaping) condition: () -> Bool)
2626
{
2727
self.init(transition: transition, condition: { t in condition() })
2828
}

0 commit comments

Comments
 (0)