Skip to content

Commit 52cd640

Browse files
committed
Merge pull request #18 from ReactKit/fix/Xcode6.3-beta2
Fix code for Xcode6.3 beta2.
2 parents cd05d71 + 70fa6aa commit 52cd640

File tree

6 files changed

+50
-28
lines changed

6 files changed

+50
-28
lines changed

SwiftState/HierarchicalStateMachine.swift

Lines changed: 1 addition & 1 deletion
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:

SwiftState/StateMachine.swift

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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>
8888
public 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

SwiftState/StateRoute.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public struct StateRoute<S: StateType>
2222
self.condition = condition
2323
}
2424

25+
public init(transition: Transition, @autoclosure(escaping) condition: () -> Bool)
26+
{
27+
self.init(transition: transition, condition: { t in condition() })
28+
}
29+
2530
public func toTransition() -> Transition
2631
{
2732
return self.transition

SwiftStateTests/StateMachineChainTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ class StateMachineChainTests: _TestCase
5050
var invokeCount = 0
5151

5252
// add 0 => 1 => 2
53-
machine.addRouteChain(.State0 => .State1 => .State2, condition: { _ in flag }) { (context) -> Void in
53+
machine.addRouteChain(.State0 => .State1 => .State2, condition: flag) { context in
5454
invokeCount++
5555
return
5656
}
57-
57+
5858
// tryState 0 => 1 => 2
5959
machine <- .State1
6060
machine <- .State2

SwiftStateTests/StateMachineTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class StateMachineTests: _TestCase
103103
var flag = false
104104

105105
// add 0 => 1
106-
machine.addRoute(.State0 => .State1, condition: { _ in flag })
106+
machine.addRoute(.State0 => .State1, condition: flag)
107107

108108
XCTAssertFalse(machine.hasRoute(.State0 => .State1))
109109

@@ -161,7 +161,7 @@ class StateMachineTests: _TestCase
161161
machine.addRoute(.State0 => .State1)
162162

163163
// add 0 => 1 with condition + conditionalHandler
164-
machine.addRoute(.State0 => .State1, condition: { _ in flag }) { context in
164+
machine.addRoute(.State0 => .State1, condition: flag) { context in
165165
returnedTransition = context.transition
166166
}
167167

SwiftStateTests/StateRouteTests.swift

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,10 @@ class StateRouteTests: _TestCase
1818
XCTAssertEqual(route.transition.toState, MyState.State1)
1919
XCTAssertTrue(route.condition == nil)
2020

21-
//
22-
// comment-out:
23-
// `condition` using lazy-evaluated-@autoclosure is removed due to Swift 1.2 change
24-
//
25-
// From Release Note:
26-
// > The @autoclosure attribute on parameters now implies the new @noescape attribute.
27-
// > This intentionally limits the power of @autoclosure to control-flow and lazy evaluation use cases.
28-
//
29-
// let route2 = StateRoute<MyState>(transition: .State1 => .State2, condition: false)
30-
// XCTAssertEqual(route2.transition.fromState, MyState.State1)
31-
// XCTAssertEqual(route2.transition.toState, MyState.State2)
32-
// XCTAssertTrue(route2.condition != nil)
21+
let route2 = StateRoute<MyState>(transition: .State1 => .State2, condition: false)
22+
XCTAssertEqual(route2.transition.fromState, MyState.State1)
23+
XCTAssertEqual(route2.transition.toState, MyState.State2)
24+
XCTAssertTrue(route2.condition != nil)
3325

3426
let route3 = StateRoute<MyState>(transition: .State2 => .State3, condition: { transition in false })
3527
XCTAssertEqual(route3.transition.fromState, MyState.State2)

0 commit comments

Comments
 (0)