@@ -16,39 +16,39 @@ enum MyState: StateType {
1616
1717``` swift
1818// setup state machine
19- let machine = Machine < MyState, NoEvent> (state : .State0 ) { machine in
20-
19+ let machine = StateMachine < MyState, NoEvent> (state : .State0 ) { machine in
20+
2121 machine.addRoute (.State0 => .State1 )
2222 machine.addRoute (.Any => .State2 ) { context in print (" Any => 2, msg=\( context.userInfo ) " ) }
2323 machine.addRoute (.State2 => .Any ) { context in print (" 2 => Any, msg=\( context.userInfo ) " ) }
24-
24+
2525 // add handler (`context = (event, fromState, toState, userInfo)`)
2626 machine.addHandler (.State0 => .State1 ) { context in
2727 print (" 0 => 1" )
2828 }
29-
29+
3030 // add errorHandler
3131 machine.addErrorHandler { event, fromState, toState, userInfo in
32- print (" [ERROR] \( transition. fromState ) => \( transition. toState ) " )
32+ print (" [ERROR] \( fromState ) => \( toState ) " )
3333 }
3434}
3535
3636// initial
37- XCTAssertTrue (machine.state == .State0 )
38-
37+ XCTAssertEqual (machine.state , MyState .State0 )
38+
3939// tryState 0 => 1 => 2 => 1 => 0
4040
4141machine <- .State1
42- XCTAssertTrue (machine.state == .State1 )
43-
42+ XCTAssertEqual (machine.state , MyState .State1 )
43+
4444machine <- (.State2 , " Hello" )
45- XCTAssertTrue (machine.state == .State2 )
46-
45+ XCTAssertEqual (machine.state , MyState .State2 )
46+
4747machine <- (.State1 , " Bye" )
48- XCTAssertTrue (machine.state == .State1 )
49-
48+ XCTAssertEqual (machine.state , MyState .State1 )
49+
5050machine <- .State0 // fail: no 1 => 0
51- XCTAssertTrue (machine.state == .State1 )
51+ XCTAssertEqual (machine.state , MyState .State1 )
5252```
5353
5454This will print:
@@ -72,17 +72,17 @@ enum MyEvent: EventType {
7272
7373``` swift
7474let machine = StateMachine< MyState, MyEvent> (state : .State0 ) { machine in
75-
75+
7676 // add 0 => 1 => 2
77- machine.addRoute (event : .Event0 , transitions : [
77+ machine.addRoutes (event : .Event0 , transitions : [
7878 .State0 => .State1 ,
7979 .State1 => .State2 ,
8080 ])
8181}
82-
82+
8383// initial
8484XCTAssertEqual (machine.state , MyState.State0 )
85-
85+
8686// tryEvent
8787machine <-! .Event0
8888XCTAssertEqual (machine.state , MyState.State1 )
@@ -191,6 +191,7 @@ For more examples, please see XCTest cases.
191191- Route Chaining: ` .State0 => .State1 => .State2 `
192192- Hierarchical State Machine: [ #10 ] ( https://github.com/ReactKit/SwiftState/pull/10 )
193193
194+
194195## Terms
195196
196197Term | Type | Description
0 commit comments