Skip to content

Commit 439d5a8

Browse files
committed
Organize code.
1 parent bfd9ed2 commit 439d5a8

File tree

2 files changed

+46
-49
lines changed

2 files changed

+46
-49
lines changed

SwiftState/EventType.swift

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,47 +8,6 @@
88

99
public protocol EventType: Hashable {}
1010

11-
// MARK: _Event (internal)
12-
13-
internal enum _Event<E: EventType>: Hashable
14-
{
15-
case Some(E)
16-
case Any // represents any `Some(E)` events but not `.None`
17-
case None // default internal value for `addRoute()` without event
18-
19-
internal var hashValue: Int
20-
{
21-
switch self {
22-
case .Some(let x): return x.hashValue
23-
case .Any: return -4611686018427387904
24-
case .None: return -4611686018427387905
25-
}
26-
}
27-
28-
internal var value: E?
29-
{
30-
switch self {
31-
case .Some(let x): return x
32-
default: return nil
33-
}
34-
}
35-
}
36-
37-
internal func == <E: Hashable>(lhs: _Event<E>, rhs: _Event<E>) -> Bool
38-
{
39-
return lhs.hashValue == rhs.hashValue
40-
}
41-
42-
internal func == <E: Hashable>(lhs: _Event<E>, rhs: E) -> Bool
43-
{
44-
return lhs.hashValue == rhs.hashValue
45-
}
46-
47-
internal func == <E: Hashable>(lhs: E, rhs: _Event<E>) -> Bool
48-
{
49-
return lhs.hashValue == rhs.hashValue
50-
}
51-
5211
// MARK: Event (public)
5312

5413
/// `EventType` wrapper for handling`.Any` event.
@@ -100,4 +59,46 @@ public enum NoEvent: EventType
10059
public func == (lhs: NoEvent, rhs: NoEvent) -> Bool
10160
{
10261
return true
103-
}
62+
}
63+
64+
// MARK: _Event (internal)
65+
66+
/// Internal `EventType` wrapper for `Event` + `Optional` + `Hashable`.
67+
internal enum _Event<E: EventType>: Hashable
68+
{
69+
case Some(E)
70+
case Any // represents any `Some(E)` events but not `.None`, for `addRouteEvent(.Any)`
71+
case None // default internal value for `addRoute()` without event
72+
73+
internal var hashValue: Int
74+
{
75+
switch self {
76+
case .Some(let x): return x.hashValue
77+
case .Any: return -4611686018427387904
78+
case .None: return -4611686018427387905
79+
}
80+
}
81+
82+
internal var value: E?
83+
{
84+
switch self {
85+
case .Some(let x): return x
86+
default: return nil
87+
}
88+
}
89+
}
90+
91+
internal func == <E: Hashable>(lhs: _Event<E>, rhs: _Event<E>) -> Bool
92+
{
93+
return lhs.hashValue == rhs.hashValue
94+
}
95+
96+
internal func == <E: Hashable>(lhs: _Event<E>, rhs: E) -> Bool
97+
{
98+
return lhs.hashValue == rhs.hashValue
99+
}
100+
101+
internal func == <E: Hashable>(lhs: E, rhs: _Event<E>) -> Bool
102+
{
103+
return lhs.hashValue == rhs.hashValue
104+
}

SwiftState/Machine.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,6 @@ public class Machine<S: StateType, E: EventType>
8181
return false
8282
}
8383

84-
public func hasRoute(fromState fromState: S, toState: S, forEvent event: E, userInfo: Any? = nil) -> Bool
85-
{
86-
return self.hasRoute(fromState: fromState, toState: toState, forEvent: .Some(event), userInfo: userInfo)
87-
}
88-
8984
///
9085
/// Check for `_routes`.
9186
///
@@ -102,8 +97,9 @@ public class Machine<S: StateType, E: EventType>
10297
var transitionDicts: [[Transition<S> : [String : Condition?]]] = []
10398

10499
if let event = event {
105-
for (ev, transitionDict) in self._routes {
106-
if ev.value == event || ev == .Any { // NOTE: no .Default
100+
for (_event, transitionDict) in self._routes {
101+
// NOTE: `_event = .None` should be excluded
102+
if _event.value == event || _event == .Any {
107103
transitionDicts += [transitionDict]
108104
}
109105
}

0 commit comments

Comments
 (0)